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

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

Powered by : @r_channels & @reddit2telegram
Download Telegram
LUA binding for Dart

Has someone a good tutorial, how to create a LUA binding for Dart via ffi? I want to create one for an old version, because we want to transfer old compiled lua code into a Flutter app.

Can someone help?

https://redd.it/1izjo4j
@r_lua
Generating UUIDs and getting current time with just a standard Lua library

Hello, I am trying to create an API Gateway with Krakend which would take an incoming HTTP request, transform it's body and then post it onto a RabbitMQ queue. To transform it, I need to write a Lua noscript, which among other things, would have to add the current time and generate a unique UUID. Problem is though, there is a certain, huge limitation for Lua on Krakend (info from it's documentation):

>Because Lua runs sandboxed in a virtual machine, there is certain stuff you cannot do. When you include files, you should limit your logic to creating functions and referencing them in different places.

>In addition to that, the usage of modules would require KrakenD to push them in advance to the virtual machine, so user-created modules are not possible. Package managers like LuaRocks are not supported either, because they inject modules globally in the system, not in the virtual machine.


As soon as I try to use methods such a math, or os.time(), which are needed for generating UUIDs or setting the current time, the noscript fails. I haven't written any Lua code before, so my question is, does anyone have any idea on how to solve this problem? Or maybe someone has an experience with Krakend and solved a similiar issue?

https://redd.it/1izkg6f
@r_lua
any apps i can use to code

I really want to get into programming I have a book to learn lua since i head its an easier ish one but I'm finding it hard to find an app to use to run and write lua if anyone has a good let me know thanks.

https://redd.it/1izsyb2
@r_lua
How to start noscripting Fivem

How to learn lua for Fivem. I don't have any knowledge about lua or any other languages. Is there any tutorials online, but from beginning to end. Like how to start Fivem server, what to do after and so on. Thanks

https://redd.it/1izubuk
@r_lua
Lua Linters/static analysis

Hi! I have recently inherited a medium sized Lua project in work (I have never worked with Lua before) and I am wanting to add linting and maybe some static analysis if that is possible (why this was never done before I do not know). When looking around I noticed that the likes of luacheck and luainspect do not seem to be actively maintained looking at the githubs.

What are people generally using for this? Are these tools feature complete, or is there something modern I am missing?

Thanks in advance!

https://redd.it/1j09lrw
@r_lua
using metatables to the fullest

Hi folks, I'm currently getting into game development using Lua. Overall I'm having a ton of fun and it's a nice language to work on. I plan to use love for the gui but for now im writing the game logic in pure Lua with no external packages.

Now the three things I hear as Lua's selling points are: easy to use, easy to embed, fast, and metatables. I understand that meta ables are supposed to be minimalist and highly flexible, but all I'm using it now currently is to use it to create structs, which in turn is used to create classes and objects. And with what I'm currently doing... I don't feel like I'm using it to the fullest. I mean, aside of Lua's other strengths, if I'm only going to use it to initialize new data types, I might as well use Python for my game.

So I'm wondering if any of you folks have general tips on how I can maximize the power of metatables? In my current state I haven't found reason to use something like, say, operator overloading (I know there's lots of examples about vector operations).

Are there some metatable wizardry that would be neat to know about? Would greatly appreciate if any of you folks have suggestions or advice!

p.s. Im using Lua over Python partly because I work with Python everyday and want to try something fresh.

https://redd.it/1j0df14
@r_lua
Standard library ignores ENV + a fix for require

Hi all,

I've been in a couple cases where I want to overload functions in `
ENV without touching G`, and found myself quite disappointed with the Lua standard library's behavior of using exclusively `G as opposed to indexing ENV`. Here's a quick demo:

local vanilla
next = next
ENV = setmetatable({ next = function (...)
print("Next!")

return vanilla
next(...)
}, { index = G })

-- We'd expect this block to result in a bunch of messages printed,
-- as pairs() uses next()
for
in pairs({ 1, 2, 3 }) do end

Looking at the source I can see why this decision was made - indexing a global is wasteful O(n) [presumably\] when lua_pushcfunction is O(1) [any other C API operation would have this benefit too, as the C API knows the addresses of tables such as package\]. However, the resulting behaviour feels un-lualike to me -- Lua provides metaprogramming facilities, and those facilities allow us to containerize global environments with _ENV, yet library functions within _ENV will rely on an environment that is 'out of scope'.

A possible solution, of course, is to re-implement globals where neccessary in pure lua - I've done so to require() in this gist, but this feels inelegant to me.

From what I know of the C API, I think a better solution is possible. When _ENV or some field of _ENV is assigned to, the API could update a struct that maintains up-to-date pointers to Lua's globals. On garbage collection the same could happen -- although it would be inconvient, setting next=nil should break pairs, which the Lua reference and Programming In Lua imply.

I'd like other people's input on this -- has it been a problem for you before, and what solutions have you used?

https://redd.it/1j0jg0g
@r_lua
How to reset/exit from a loop in lua - for BeamNG Multiplayer (BeamMP)

Hi Guys, I'm not sure this is the correct community to post this. It's either this or BeamNG, but I put my money on this one. I made a noscript to start a countdown timer that will be visible to all players in my BeamNG multiplayer server's chat. The idea is that when someone writes in chat "/starttimer [timer in seconds\]" it will initite a countdown and show the progress in the chat. This is already working (I will share the code). However I would like to have the option to reset the countdown. No matter what I try, when it gets to the "for" loop it no longer reads new chat messages (e.g. /stoptimer) . I have tried chatgpt, they suck. Any suggestions?

https://redd.it/1j0ktg2
@r_lua
HPLN web stack

I made a very simple web stack to play around with writing back ends in Lua: https://hpln.burij.de . It is something I wouldn't recommend using in production, but it's a lot of fun. It is based on Nix, Lua module in Nginx, Pico CMS and HTMX. If you're already using Nix or NixOS you should be able to spin up a dev environment with one command. If not, you're welcome to check out the code. The website is also deployed on NixOS homebrew server. Every idea or advice for further development are of course welcome (still learning)!

https://redd.it/1j0xj1m
@r_lua
Molvez Community Addon Wow

# Molvez_Addon

The first community addon !

Hello everyone! Welcome to the first community addon! Molvez

A UNIQUE addon that needs nothing but itself. An addon that takes everything into account: UI, collection, quests, details, chat, etc. etc... Here you can share your ideas, talk about anything and everything. My name is Pierre, and I'm pretty good at photo editing and I'm learning LUA Code, so I thought, why not practice on a wow addon. Might as well combine business with pleasure, right?

So I'm slowly learning, but even if I'm able to define frames graphically, I'm not yet at the level to create such a major addon on my own.

So I'm defining the addon's graphic approach, and if you'd like to take part in the coding, I'd be delighted to!

[https://discord.gg/zFPrryq8](https://discord.gg/zFPrryq8)

created by the players themselves

https://redd.it/1j0x21x
@r_lua
ZeroBrane Studio WX Error

WX doesn't exist for some reason when I try to use "require("wx")", it says the wx.dll and etc doesn't exist at all, and when I check, it's not there, how do I download it? Or is it an error that shouldn't happen.

It also doesn't work with Turtle.lua.

The error. .\\turtle.lua:9: module 'wx' not found:

no field package.preload['wx'\]

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\bin\\lua\\wx.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\bin\\lua\\wx\\init.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\bin\\wx.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\bin\\wx\\init.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\bin\\..\\share\\lua\\5.4\\wx.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\bin\\..\\share\\lua\\5.4\\wx\\init.lua'

no file '.\\wx.lua'

no file '.\\wx\\init.lua'

no file './wx.lua'

no file './wx/init.lua'

no file './lua/wx.lua'

no file './lua/wx/init.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\lualibs/wx/wx.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\lualibs/wx.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\lualibs/wx/wx/init.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\lualibs/wx/init.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\lualibs/wx.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\lualibs/wx/wx.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\lualibs/wx/init.lua'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\bin/clibs54/wx.dll'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\bin\\wx.dll'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\bin\\..\\lib\\lua\\5.4\\wx.dll'

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\bin\\loadall.dll'

no file '.\\wx.dll'

no file ''

no file 'C:\\Users\\(My name)\\Downloads\\ZeroBraneStudio\\bin/clibs54/wx.dll'

https://redd.it/1j1a3po
@r_lua
I'm trying to convert markdown to pdf in lua but I have some questions about file systems

Hey, I want to make my own markdown to pdf convertor in lua, since I have a bunch of markdown in one of my qownnotes folders that is meant to be a book, and I want to learn how to generate files with lua. I know one could just read the files in the directory of wherever the lua noscript is, and be done with it, but how do I move to whatever directory the markdown folder is and then convert the files from there?

sorry if this doesn't make sense, I am a hobbyist coder just getting into it

https://redd.it/1j1bvx3
@r_lua
New to lua

Hi everyone, im new to lua and im tryna get better at it. What is the best way to learn? I know all of the basics, but i wanna know more



https://redd.it/1j1qba6
@r_lua
Plume - A templating langage that transpile to lua

I had already posted here (with another account) about "Plume", a Lua-extensible template language. github

Since then, I've completely restarted the project from scratch, reaching a result that I find vastly better ^(')

Plume is a template language that transpiles to Lua. You can test it here. Except for function calls, which aren't yet optimized, I find the transpiled code to be rather clean and efficient!

The transpiler is also written in Lua, and Plume can contain arbitrary Lua expressions, making it very easy to include in an existing ecosystem.

If you want a glimpse of the language, think of it as a hybrid of YAML and Lua!

myTable =
key: value
- foo
- bar
- baz

My key is $(myTable.value)

for i, x in ipairs(myTable)
myTable item n°$i is $x!
The cos of $i is $(math.cos(i))




https://redd.it/1j1uomq
@r_lua
Personal beginner's project - looking for feedback on a Monopoly money counter

Hello all! I'm attempting to teach myself Lua, starting from a very limited knowledge of programming in general, and I decided to start off by writing a simple money counter for a game like Monopoly. For an added challenge, I attempted to add a layer of "idiot proofing": if you enter in a bad number or a wrong name, the program will prompt you to try again until you get it right. Here's what I've got so far:

-- a counter for monopoly money

-- this table contains all the players' names
Players = {}

-- this function displays the remaining money of all the players in the game
function DisplayTable(table)
for k,v in pairs(table) do
if v == 0 then
print(k .. " is bankrupt")
else
print(k .. " has " .. v)
end
end
end

-- this function checks a name against the table of names to see if you put in a valid input
function FilterName(table)
while true do
Name = io.read("l")
if Name ~= "Bank" and tableName == nil then
print("I don't recognize that name. Try a different name.")
elseif tableName == 0 then
print("That player is bankrupt! Try a different player.")
else
return Name
end
end
end

-- this function checks your input and filters it into a number between a specified range
function InputRange(start, stop)
while true do
Input = math.tointeger(io.read("l"))
if Input == nil then
print("That's not a valid input. Please try again.")
elseif Input < start or Input > stop then
print("That number is out of range. Please try again.")
else
return Input
end
end
end

-- this function filters out the bank every time money changes hands
function NotBank(gained, lost, amount, table)
if gained ~= "Bank" then
tablegained = tablegained + amount
end
if lost ~= "Bank" then
tablelost = tablelost - amount
end
end

-- this function makes sure that you don't put the same name twice for gaining and losing money
function NeedTwoNames(gained, table)
while true do
print("Who lost money?")
Lost = FilterName(table)
if gained == Lost then
print("You need two different names here.")
else
return Lost
end
end
end

-- this function checks to see if someone has won the game
-- this function isn't designed to handle what might happen if everyone went to zero, but hopefully that won't happen
function WinnerCheck(table)
StillAlive = 0
Winner = nil
for k, v in pairs(table) do
if v ~= 0 then
Winner = k
StillAlive = StillAlive + 1
if StillAlive > 1 then
return false
end
end
end
return Winner
end


print("Welcome to Monopoly Money Counter, the noscript that counts your money so you don't have to!\nTo read the full instructions, type in \"info\". Otherwise, type in \"start\" to get started.")
while true do
Input1 = io.read("l")
if Input1 == "info" then
print("When you start the game, you'll be prompted to enter in the names of 2 to 6 players. After entering in names, you'll then have the option of transferring money to and from players, either between players or between the player and the bank, named \"Bank\". Speaking of which, don't name any of your players \"Bank\", since that name is taken!\nIf a player would reach 0 dollars, you'll be asked to confirm whether or not you want that to happen, because going to 0 means that the player is bankrupt and out of the game. Once a player is out of
Personal beginner's project - looking for feedback on a Monopoly money counter

Hello all! I'm attempting to teach myself Lua, starting from a *very* limited knowledge of programming in general, and I decided to start off by writing a simple money counter for a game like Monopoly. For an added challenge, I attempted to add a layer of "idiot proofing": if you enter in a bad number or a wrong name, the program will prompt you to try again until you get it right. Here's what I've got so far:

-- a counter for monopoly money

-- this table contains all the players' names
Players = {}

-- this function displays the remaining money of all the players in the game
function DisplayTable(table)
for k,v in pairs(table) do
if v == 0 then
print(k .. " is bankrupt")
else
print(k .. " has " .. v)
end
end
end

-- this function checks a name against the table of names to see if you put in a valid input
function FilterName(table)
while true do
Name = io.read("l")
if Name ~= "Bank" and table[Name] == nil then
print("I don't recognize that name. Try a different name.")
elseif table[Name] == 0 then
print("That player is bankrupt! Try a different player.")
else
return Name
end
end
end

-- this function checks your input and filters it into a number between a specified range
function InputRange(start, stop)
while true do
Input = math.tointeger(io.read("l"))
if Input == nil then
print("That's not a valid input. Please try again.")
elseif Input < start or Input > stop then
print("That number is out of range. Please try again.")
else
return Input
end
end
end

-- this function filters out the bank every time money changes hands
function NotBank(gained, lost, amount, table)
if gained ~= "Bank" then
table[gained] = table[gained] + amount
end
if lost ~= "Bank" then
table[lost] = table[lost] - amount
end
end

-- this function makes sure that you don't put the same name twice for gaining and losing money
function NeedTwoNames(gained, table)
while true do
print("Who lost money?")
Lost = FilterName(table)
if gained == Lost then
print("You need two different names here.")
else
return Lost
end
end
end

-- this function checks to see if someone has won the game
-- this function isn't designed to handle what might happen if everyone went to zero, but hopefully that won't happen
function WinnerCheck(table)
StillAlive = 0
Winner = nil
for k, v in pairs(table) do
if v ~= 0 then
Winner = k
StillAlive = StillAlive + 1
if StillAlive > 1 then
return false
end
end
end
return Winner
end


print("Welcome to Monopoly Money Counter, the noscript that counts your money so you don't have to!\nTo read the full instructions, type in \"info\". Otherwise, type in \"start\" to get started.")
while true do
Input1 = io.read("l")
if Input1 == "info" then
print("When you start the game, you'll be prompted to enter in the names of 2 to 6 players. After entering in names, you'll then have the option of transferring money to and from players, either between players or between the player and the bank, named \"Bank\". Speaking of which, don't name any of your players \"Bank\", since that name is taken!\nIf a player would reach 0 dollars, you'll be asked to confirm whether or not you want that to happen, because going to 0 means that the player is bankrupt and out of the game. Once a player is out of
the game, you can't transfer any money to or from them.\nThis program doesn't keep track of any properties or houses. You'll have to do that yourself. This is only for counting money. This program is also not designed to keep track of any money in the \"Free Parking\" space. Sorry, folks.\nTo read this again, type in \"info\". Otherwise, type in \"start\" to get started.")
elseif Input1 == "start" then
print("Let's get started!")
break
else
print("Sorry, bad input. Can you try that again?")
end
end

print("How many players do you have? Put in a number between 2 and 6.")
Amount = InputRange(2, 6)

print("What are your players' names?")
for i = 1, Amount do
while true do
Input3 = io.read("*l")
if Input3 == "Bank" then
print("Sorry, that's the bank's name! Try a different name. Perhaps a nickname?")
elseif Players[Input3] == 1500 then
print("Sorry, that name's taken! Try a different name. Perhaps a nickname?")
else
Players[Input3] = 1500
break
end
end
end

print("Let's play the game!")
DisplayTable(Players)
while true do
while true do
print("Who gained money?")
GainedMoney = FilterName(Players)
LostMoney = NeedTwoNames(GainedMoney, Players)
print("How much money?")
MoneyChange = InputRange(0, 1000000)
if LostMoney ~= "Bank" and MoneyChange >= Players[LostMoney] then
print("This will bankrupt " .. LostMoney .. ". Are you sure? Type \"yes\" or \"no\".")
ConfirmChoice = io.read("l")
if ConfirmChoice ~= "yes" and ConfirmChoice ~= "no" then
print("Try again. \"yes\" or \"no\"")
elseif ConfirmChoice == "no" then
print("Then let's try this all over again")
break
else
MoneyChange = Players[LostMoney]
NotBank(GainedMoney, LostMoney, MoneyChange, Players)
break
end
else
NotBank(GainedMoney, LostMoney, MoneyChange, Players)
break
end
end
DisplayTable(Players)
Winner = WinnerCheck(Players)
if Winner ~= false then
print(Winner .. " has won!")
break
end
end-- a counter for monopoly money


-- this table contains all the players' names
Players = {}


-- this function displays the remaining money of all the players in the game
function DisplayTable(table)
for k,v in pairs(table) do
if v == 0 then
print(k .. " is bankrupt")
else
print(k .. " has " .. v)
end
end
end


-- this function checks a name against the table of names to see if you put in a valid input
function FilterName(table)
while true do
Name = io.read("l")
if Name ~= "Bank" and table[Name] == nil then
print("I don't recognize that name. Try a different name.")
elseif table[Name] == 0 then
print("That player is bankrupt! Try a different player.")
else
return Name
end
end
end


-- this function checks your input and filters it into a number between a specified range
function InputRange(start, stop)
while true do
Input = math.tointeger(io.read("l"))
if Input == nil then
print("That's not a valid input. Please try again.")
elseif Input < start or Input > stop then
print("That number is out of range. Please try again.")
else
return Input
end
end
end


-- this function filters out the bank every time money changes
hands
function NotBank(gained, lost, amount, table)
if gained ~= "Bank" then
table[gained] = table[gained] + amount
end
if lost ~= "Bank" then
table[lost] = table[lost] - amount
end
end


-- this function makes sure that you don't put the same name twice for gaining and losing money
function NeedTwoNames(gained, table)
while true do
print("Who lost money?")
Lost = FilterName(table)
if gained == Lost then
print("You need two different names here.")
else
return Lost
end
end
end


-- this function checks to see if someone has won the game
-- this function isn't designed to handle what might happen if everyone went to zero, but hopefully that won't happen
function WinnerCheck(table)
StillAlive = 0
Winner = nil
for k, v in pairs(table) do
if v ~= 0 then
Winner = k
StillAlive = StillAlive + 1
if StillAlive > 1 then
return false
end
end
end
return Winner
end



print("Welcome to Monopoly Money Counter, the noscript that counts your money so you don't have to!\nTo read the full instructions, type in \"info\". Otherwise, type in \"start\" to get started.")
while true do
Input1 = io.read("l")
if Input1 == "info" then
print("When you start the game, you'll be prompted to enter in the names of 2 to 6 players. After entering in names, you'll then have the option of transferring money to and from players, either between players or between the player and the bank, named \"Bank\". Speaking of which, don't name any of your players \"Bank\", since that name is taken!\nIf a player would reach 0 dollars, you'll be asked to confirm whether or not you want that to happen, because going to 0 means that the player is bankrupt and out of the game. Once a player is out of the game, you can't transfer any money to or from them.\nThis program doesn't keep track of any properties or houses. You'll have to do that yourself. This is only for counting money. This program is also not designed to keep track of any money in the \"Free Parking\" space. Sorry, folks.\nTo read this again, type in \"info\". Otherwise, type in \"start\" to get started.")
elseif Input1 == "start" then
print("Let's get started!")
break
else
print("Sorry, bad input. Can you try that again?")
end
end


print("How many players do you have? Put in a number between 2 and 6.")
Amount = InputRange(2, 6)


print("What are your players' names?")
for i = 1, Amount do
while true do
Input3 = io.read("*l")
if Input3 == "Bank" then
print("Sorry, that's the bank's name! Try a different name. Perhaps a nickname?")
elseif Players[Input3] == 1500 then
print("Sorry, that name's taken! Try a different name. Perhaps a nickname?")
else
Players[Input3] = 1500
break
end
end
end


print("Let's play the game!")
DisplayTable(Players)
while true do
while true do
print("Who gained money?")
GainedMoney = FilterName(Players)
LostMoney = NeedTwoNames(GainedMoney, Players)
print("How much money?")
MoneyChange = InputRange(0, 1000000)
if LostMoney ~= "Bank" and MoneyChange >= Players[LostMoney] then
print("This will bankrupt " .. LostMoney .. ". Are you sure? Type \"yes\" or \"no\".")
ConfirmChoice = io.read("l")
if ConfirmChoice ~= "yes" and ConfirmChoice ~= "no" then
print("Try again. \"yes\" or \"no\"")
elseif ConfirmChoice == "no" then
print("Then let's try this all over
again")
break
else
MoneyChange = Players[LostMoney]
NotBank(GainedMoney, LostMoney, MoneyChange, Players)
break
end
else
NotBank(GainedMoney, LostMoney, MoneyChange, Players)
break
end
end
DisplayTable(Players)
Winner = WinnerCheck(Players)
if Winner ~= false then
print(Winner .. " has won!")
break
end
end

So far, it seems to work! What I'd like help on is making it better. When you look at this, how would you make it prettier or more efficient? Does anything stand out to you as a bad thing to do? Are there any bugs that I've missed?

Thanks in advance for your time. This language is fun!

https://redd.it/1j1wnbg
@r_lua
Full Program in Pure Lua?

I want to make a simple, shippable program in pure Lua, but for the life of cannot find how to do it.

I'm new to Lua and have been loving it. I was introduced to it through the Love game framework and want to use it to make more little CLI apps, but I can't find how to package things into a single file executable that I could easily share. The only way I know how to run a Lua program is 'lua file.lua' How can I turn Lua files into a packaged and installable program?

Is luarocks my answer? It feels like a thing for libraries and not full programs, or do I misunderstand it?

Are pure Lua programs not really the language's intend use case?

Thanks!

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