Lua - Reddit – Telegram
Lua - Reddit
31 subscribers
281 photos
31 videos
4.28K links
News and discussion for the Lua programming language.

Subreddit: https://www.reddit.com/r/lua

Powered by : @r_channels & @reddit2telegram
Download Telegram
Error with gsub()

This line doesnt seem to work and I don't know why

suffix = noscript:gsub(" ", "-"):gsub("^A-Za-z0-9-", ""):lower()

https://redd.it/1eltnj0
@r_lua
I just released a new Application Development Framework made with lua.
https://redd.it/1enyam1
@r_lua
how to get used to the lack of data types

I'm coming from python primarily, although I've dabbled in c/c++ and have taken a look at rust. (didn't get very far though lol)

but the lack of built in data types and containers is throwing me for a loop, especial containers, I'm used to having some sort of generic "constructor" may that be through structs or classes or the like, and using those as my primary organization for data.

for example a tile structure that takes a X and a Y and a color, i know this sort of thing is possible but from what i've seen its kind of difficult

https://redd.it/1eoebdl
@r_lua
New mailing list subnoscription

With the old lua-l mailing list closed down and moved to Google Groups, I followed the subnoscription instructions to subscribe to the new one. I send the subnoscription email, and get a confirmation email back, but when I reply to that one to confirm the subnoscription, I get a "Delivery Status Notification (Failure)" reply back with this error:

The response was:

Unexpected DFS AddMemberships membership status

I've tried this a few times with the same response each time. Has anyone else run into problems trying to subscribe to the mailing list?

https://redd.it/1eolujn
@r_lua
Working on Lua code for a CYF project. I was making different text appear every time you did something. I did this for a Lie command and Threaten command and wrote this statement |elseif command == "LIE" then| and did the same for Threaten. |elseif command == "THREATEN"| But Lie showed me an error

So I need help with this. Also, the lines after each line of code are borders, not the code itself. I'm new to Lua btw so I may have made a few mistakes or two. FYI it's on line 51

The Code



https://redd.it/1eoyqgl
@r_lua
coding Multiplayer with steam API

i like playing a game, i have its source and want to mod it, I want to add multiplayer to it using steams API, but it doesnt support modding, would be be possible?

https://redd.it/1ep3bsu
@r_lua
keep information when replacing using string.gsub()?

I'm trying to find all instance of a non-digit character followed by a period followed by any number of digit characters and essentially put a zero infront of the period.

i currently have :

string.gsub(str, '%D%.%d+', '0.') but it replaces the entire section with '0.' (obviously), how could i retain information when replacing; i essentially want to turn the: '%D%.%d+' into '%D0%.%d+' instead of replacing it entirely.I have thought about using string.gmatch to get the information in a for loop but i cant find a way to also return the index of the character at the start of the match.

because of the current structure of my code though i would definitely preffer if the solution is just a slightly longer line of code or at least short but if its not possible then whatever works.

https://redd.it/1ep5kep
@r_lua
OOP in lua with lua-classic

The project repository: https://github.com/Rizwanelansyah/lua-classic/

this library is used for my next project, if you have a feedback please tell me.

an simple usage:

local class = require 'classic.class'

local MyClass = {}
class(MyClass, function(C)
MyClass.foo = 10
C.public()
MyClass.bar = 0

function MyClass:init(foo)
self.foo = foo
end

function MyClass:print()
print('Foo: ' .. self.foo .. ', Bar: ' .. self.bar)
end
end)

local obj = MyClass.new(14)
obj:print() --> Foo: 14, Bar: 0
-- obj.foo = 60 --> this line will error because field foo is private
obj.bar = 10
MyClass.print(obj) --> Foo: 14, Bar: 10

https://redd.it/1epdhym
@r_lua
Beginner issue

So I have been trying to get into coding for a while and since I have a lot of time on my hands just sort of went for it, I installed everything needed (Vsc, Lua) I was also sure to put lua in the program files folder ( For reference the directory is C:\\Program Files\\Lua ) I was also sure to put everything needed on the environmental variable settings, I know this installed lua properly to a degree since I can run it on cmd. atm I haven't tried anything more than hello world text but I'm not sure how relevant that is. But now when I tried to run it on vsc it showed up with this error.

https://preview.redd.it/u99tbjsmv4id1.png?width=1857&format=png&auto=webp&s=73965f6275dabed28c0a8d1af1f8bdddd70b3415

Now the tutorial I followed was this one https://www.youtube.com/watch?v=rol8n3FYtuU&t=218s I pretty much copied everything the guy did including the names of all my files and stuff. If it helps in anyway I am also using windows 11 and the specific version of lua I installed is lua 5.3.6 any and all help is very much appreciated.

https://redd.it/1eq15r4
@r_lua
Lua = AWESOME * 1000 for Game Development.

I know you're saying Duh.......

I saw a video about the Playdate SDK and I thought that would be cool to make a game for my Son. Learned some basics of Lua, and then I see LÖVE 2D and I'm like get outta here with how easy it is to make a game with Lua.

Lua rocks man!!!!

https://redd.it/1eqpcb6
@r_lua
Need help with the line draw feature of .lua

Hello all,

I am on Linux Mint, working with an application named Conky that has the ability to run .lua noscripts.

One of my conky widgets runs a .lua noscript that has a section that draws lines. This section draws a long horizontal line with a diagonal line attached at the top of diagonal and left end of horizontal lines:

--cpu4

cairo_move_to(cr, pozycja_x + 26 + math.cos(nwsk * -9.202 / 2000) * (promien_cpu0 + width_cpu0) + 8 * 4, pozycja_y - math.sin(nwsk * -9.202 / 2000) * (promien_cpu0 + width_cpu0) + 12 * 2)

cairo_line_to(cr, pozycja_x + math.cos(nwsk * 3.202 / 1200) * ramie_cpu0, pozycja_y - math.sin(nwsk * 3.202 / 1200) * ramie_cpu0)

cairo_line_to(cr, pozycja_x + math.cos(nwsk * 3.202 / 1200) * ramie_cpu0 + 124, pozycja_y - math.sin(nwsk * 3.202 / 1200) * ramie_cpu0)

cairo_stroke(cr)

cairo_move_to(cr, pozycja_x + math.cos(nwsk * 3.202 / 1200) * ramie_cpu0 + txtxoffset, pozycja_y - math.sin(nwsk * 3.202 / 1200) * ramie_cpu0 - txtyoffset)

cairo_show_text(cr, "cpu4: " .. conky_parse("${cpu cpu4}") .. "%, " .. conky_parse("${freq_g cpu4}") .. "Ghz, " .. conky_parse("${acpitemp}") .. "°C")

cairo_stroke(cr)

The "pozycja_x" and "poxycia-y" variable are defined at the beginning of the .lua and have a value of 400 each.

I have been to chatgpt3.5 and 2-3 dedicated .lua code generating websites and nothing can edit the above code or replicate it to create a 120 pixel horizontal line with a shorter, 40 pixel diagonal line coming off it.

Here is the conky I am working with:

https://i.imgur.com/OfsLSWc.png

and the right red arrow on image points to the lines created by the above code for the cpu4 section. This is the configuration of lines I am trying to get code for, just with a diagonal line 1/3 the length of the one being currently generated.

Can anyone help please?

Thank you for reading,

Logan

https://redd.it/1eqweum
@r_lua
Plume : A logicfull text template langage, written in lua, extensible via lua

https://preview.redd.it/yfopz0uo8fid1.png?width=1957&format=png&auto=webp&s=fc2d67901b7bfbbdee78c29328303fe847c8c0fe

Hello everyone,

I've been using template systems for a long time to generate documents for my courses, so I decided to make a "clean and presentable" version.
(I'm a total self-taught programmer, and this is a passion project I'm doing in my spare time.)

Copy of the beginning of the readme :

Programming languages like Python and Lua enable the implementation of complex logic with relative ease. However, working with text input can often be tedious due to cumbersome syntax.

While there are formats that facilitate enriched text writing, such as Markdown or Jinja, they tend to have limited logical capabilities.

Plume's philosophy is to combine the best of both worlds: text input is at the core of its design, yet the integration of logic is seamless, thanks to its close relationship with the Lua noscripting language.

To illustrate, consider the task of generating ten files, each containing a multiplication table for a specific number. This can certainly be achieved in Python or Lua, but of Plume offers a more intuitive approach:

\for {i=1,10} {
\file {table-#i.txt} {
\for {j=1,10}{
#i #j = #{ij}
}
}
}

https://github.com/ErwanBarbedor/Plume\_-\_TextEngine

https://redd.it/1er66z9
@r_lua
Favourite cross-platform (Linux, Mac, Windows) GUI?

I think we all already know that the state of cross platform GUI on Lua kinda sucks, but let's hear some good ones.

Bonus points (optional):
- on Luarocks
- maintained
- actually easy to install (looking at you, windows...)
- Lua version support
- well documented

The best one I can find that furfills all of this is https://libyue.com/docs/latest/lua/ but it's not very maintained

https://redd.it/1erdzet
@r_lua
Tell me if this is a stupid question, is there anything obviously wrong with this part of a code? I know nothing about LUA and i'm just desperatly trying to get this STALKER Anomaly mod to work. The crash log says theres an error at the line at the very top. No big details needed, thank you.
https://redd.it/1erxdk2
@r_lua
Special Variables

hey,

I discovered that when running a cli app, I can pass `arg` to the function, and it will receive the command-line arguments, as described here

are there any others special variables? where can I found them?

https://redd.it/1eryu3h
@r_lua
help i cant make a file in visual code studio

https://preview.redd.it/du8fqnebmqid1.png?width=1919&format=png&auto=webp&s=1a67ccaf181dc7348b220c13a27c98e5c28dad5e

ive downloaded lua on here, but it shows some languages ive downloaded apart from lua..
really need help

https://redd.it/1esjs3m
@r_lua
how do I make it so that if the user enters the random number wrongly, a message that they have failed appears every time this happens?

Well, i was trying to make a lua program that when a random number is drawn from 0 to 10 the user must try to guess it, but if he gets it wrong i want a message to appear every time he gets it wrong, but without having to restart the program.

print("guess a number between 0 and 10")
local guess = io.read()
local rightNumber = math.random(0, 10)

if guess == rightNumber then
print("congratulations!")
elseif guess ~= rightNumber then
while true do
print("sorry the right number is " .. rightNumber .. " you failed try again")
end
end



https://redd.it/1esyv4j
@r_lua
How to add team distribution in this noscript, so that after teleportation to the map, players who were teleported are added to the Game team, and players who are in the lobby also remain in the Lobby team? Help please

local gMgr = {}
local sessionData = {}
local mSpawns = workspace.Map.Spawns:GetChildren()
local lSpawns = workspace.Lobby.Spawns:GetChildren()
local numOfPlayers = 0
local declareWinnerTime = 3
local rs = game:GetService("ReplicatedStorage")
local winnerRe = rs:WaitForChild("WinnerRe")
local intermissionRe = rs:WaitForChild("IntermissionRe")
local intermissionTime = 5

local Teams = game:GetService("Teams")
local lobbyTeam = Teams:FindFirstChild("Lobby") or Instance.new("Team", Teams)
lobbyTeam.Name = "Lobby"
local gameTeam = Teams:FindFirstChild("Game") or Instance.new("Team", Teams)
gameTeam.Name = "Game"

function gMgr:isEnoughPlayers()
if numOfPlayers > 1 then
return true
end
return false
end

function gMgr:declareWinner(player)
-- remote event to UI
winnerRe:FireAllClients(player, declareWinnerTime)
wait(declareWinnerTime)
sessionDataplayer"isWinner" = true
sessionDataplayer"wins" = sessionDataplayer"wins" + 1
for ply, data in pairs(sessionData) do
local spawnPnt = lSpawnsmath.random(1, #lSpawns)
ply.Character.HumanoidRootPart.CFrame = spawnPnt.CFrame + Vector3.new(0, 3, 0)
data"isPlaying" = false
ply.Team = lobbyTeam
end
end

function gMgr:checkForLastPlayerStanding()
local num = 0
local aPlayer = nil
for player, data in pairs(sessionData) do
if data"isPlaying" then
num = num + 1
aPlayer = player
end
end
if num == 1 then
return aPlayer
end
return nil
end

function gMgr:intermission()
intermissionRe:FireAllClients(intermissionTime)
wait(intermissionTime)
end

local function teleportPlayers()
for ply, data in pairs(sessionData) do
local spawnPnt = mSpawnsmath.random(1, #mSpawns)
ply.Character.HumanoidRootPart.CFrame = spawnPnt.CFrame + Vector3.new(0, 3, 0)
data"isWinner" = false
data"isPlaying" = true
ply.Team = gameTeam
end
end

local function checkIfAnyoneIsPlaying()
for ply, data in pairs(sessionData) do
if data"isPlaying" then
return true
end
end
return false
end

function gMgr:playGame()
local stillPlaying = true
teleportPlayers()
while stillPlaying do
stillPlaying = checkIfAnyoneIsPlaying()
wait(1)
end
end

local function addChar(char)
local player = game.Players:GetPlayerFromCharacter(char)
sessionDataplayer"isPlaying" = false
player.Team = lobbyTeam
end

local function addPlayer(player)
sessionDataplayer = { isPlaying=false, isWinner=false, wins=0 }
numOfPlayers = numOfPlayers + 1
player.CharacterAdded:Connect(addChar)
player.Team = lobbyTeam
end

local function removePlayer(player)
sessionDataplayer = nil
numOfPlayers = numOfPlayers - 1
end

game.Players.PlayerAdded:Connect(addPlayer)
game.Players.PlayerRemoving:Connect(removePlayer)

return gMgr

https://redd.it/1et1lly
@r_lua