Global and local variables with Fengari
I know that local variables allow the code to run faster than globals but does the same apply when the code is converted to javanoscript by the fengari virtual machine? The question earlier this week made me curious ;-0
https://redd.it/1iyplwe
@r_lua
I know that local variables allow the code to run faster than globals but does the same apply when the code is converted to javanoscript by the fengari virtual machine? The question earlier this week made me curious ;-0
https://redd.it/1iyplwe
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Code has and error when run locally, but runs fine when submitted to Exercism.
I'm losing my mind, hopefully one of you can help me understand what is going on.
I'm using Exercism to learn the basics of Lua. In my code, I am trying to divide a number by 2, but floor it if it's not an integer value. With Exercism, it provides a test noscript, and you run and test the code with Busted. When I run this locally, I get an error:
./eliuds-eggs\_spec.lua:1: error loading module 'eliuds-eggs' from file './eliuds-eggs.lua':
./eliuds-eggs.lua:8: unexpected symbol near '/'
I submitted it to Exercism anyway so that I could look at other people's submissions and see if anyone else did what I was trying to do, and my code passed with no issues.
What could be causing my local environment to not recognize integer division?
Lua: 5.4.7
busted: 2.2.0
The function in question (the error message is pointing to the line that says "number = (number // 2)")
function EliudsEggs.egg_count(number)
local count = 0
while (number > 0) do
count = count + (number % 2)
number = (number // 2)
end
return count
end
https://redd.it/1iyxgxx
@r_lua
I'm losing my mind, hopefully one of you can help me understand what is going on.
I'm using Exercism to learn the basics of Lua. In my code, I am trying to divide a number by 2, but floor it if it's not an integer value. With Exercism, it provides a test noscript, and you run and test the code with Busted. When I run this locally, I get an error:
./eliuds-eggs\_spec.lua:1: error loading module 'eliuds-eggs' from file './eliuds-eggs.lua':
./eliuds-eggs.lua:8: unexpected symbol near '/'
I submitted it to Exercism anyway so that I could look at other people's submissions and see if anyone else did what I was trying to do, and my code passed with no issues.
What could be causing my local environment to not recognize integer division?
Lua: 5.4.7
busted: 2.2.0
The function in question (the error message is pointing to the line that says "number = (number // 2)")
function EliudsEggs.egg_count(number)
local count = 0
while (number > 0) do
count = count + (number % 2)
number = (number // 2)
end
return count
end
https://redd.it/1iyxgxx
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
What data types can math.randomseed take?
I'm reading through some code that has uses a pseudorandom process to generate seeds for
Here's what the code is doing:
-- LCG algorithm, generates float between 0 and 1
pseudoseed1 = math.abs(tonumber(string.format("%.13f", (2.134453429141+pseudoseed*1.72431234)%1)))
-- hashedseed is also a float between 0 and 1
pseudoseed = (pseudoseed1 + hashedseed)/2
math.randomseed(pseudoseed)
print(math.random())
Is there a way to make sense of this? Running this in lua 5.4 will generate an error (since
https://redd.it/1iz63i1
@r_lua
I'm reading through some code that has uses a pseudorandom process to generate seeds for
math.randomseed, but the seeds are generated as some float between 0 and 1. Here's what the code is doing:
-- LCG algorithm, generates float between 0 and 1
pseudoseed1 = math.abs(tonumber(string.format("%.13f", (2.134453429141+pseudoseed*1.72431234)%1)))
-- hashedseed is also a float between 0 and 1
pseudoseed = (pseudoseed1 + hashedseed)/2
math.randomseed(pseudoseed)
print(math.random())
Is there a way to make sense of this? Running this in lua 5.4 will generate an error (since
math.randomseed only takes integers), and running it in lua 5.1 will result in pseudoseed being truncated to 0 when passed to math.random, giving the same exact result from math.random every time. The software definitely works at generating different numbers each time, so I feel like I'm missing something here.https://redd.it/1iz63i1
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
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
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
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
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
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
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
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
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
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
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
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
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
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
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
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
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
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
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
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
local vanillanext = next
ENV = setmetatable({ next = function (...)
print("Next!")
return vanillanext(...)
}, { 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
A possible solution, of course, is to re-implement globals where neccessary in pure lua - I've done so to
From what I know of the C API, I think a better solution is possible. When
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
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 vanillanext = next
ENV = setmetatable({ next = function (...)
print("Next!")
return vanillanext(...)
}, { 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
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
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
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
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
# 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
Discord
Join the Molvez_Addon Discord Server!
Check out the Molvez_Addon community on Discord - hang out with 1 other members and enjoy free voice and text chat.
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
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
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
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
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
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
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
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
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
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
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
GitHub
GitHub - ErwanBarbedor/PlumeScript: Powerfull Templating Language
Powerfull Templating Language. Contribute to ErwanBarbedor/PlumeScript development by creating an account on GitHub.
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
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
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
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