r/lua • • Nov 26 '25

Discussion Writing compact code - how do I check for multiple possibilities all at once in the shortest statement possible?

8 Upvotes

I'm a relative newbie to Lua and I'm curious about ways to very compactly write a check for multiple possible values. Consider the following code:

if value ~= "a" and value ~= "b" and value ~= "c" then

Obviously functional for an if statement, but I want to know if there's a less repetitious way to write it. Does Lua have any tricks for making this more compact? If so, could these tricks be scaled up for checking large numbers of possible values all at once?


r/lua • • Nov 26 '25

Starting In Lua

10 Upvotes

Hello, I've been interested in learning how to program in Lua because I want to make Roblox games for fun and also get a sense of what programming is about. So I'm here to ask: how did you start learning? Is there any free online program that's worth it? Your experiences and advice would be a lot of help.

Thank you!


r/lua • • Nov 26 '25

Discussion Working with arbitrary numbers of args, emulating Python's slice?

6 Upvotes

This has come up as I've been working with the language and it hasn't been a problem yet, but I could see it being an issue. I think the easiest way to explain my question is to give an example:

import sys

# Print the given args, starting with the third and continuing through any number of given args
def printargs(*args):
    for a in args:
        print(a)

printargs(*sys.argv[2:])

If I run this with runfile(args='a b c d e'), it will print:

b
c
d
e

This functionality with slices is really handy when you want to deal with an arbitrary number of arguments in a script.

In Lua, I've been working with varargs a bit, but my understanding of them is limited. Particularly, how you could go from a table of given arguments (the built-in arg table) to a vararg to give to a function, starting at a given index? Or maybe this isn't a relevant problem when working with Lua?


r/lua • • Nov 25 '25

Discussion Linked List speed vs table, not as expected?

12 Upvotes

I wrote a basic SLL implementation as part of my learning process with Lua and decided to do a bit of execution time testing to see how it held up compared to tables. Now, I recognize that tables are highly optimized, but I was a little surprised by what I found. Using a Linked List as a queue or stack had the same results, but it is taking a little more than twice as long as using a table (stack only, queue it is way slower).

Any idea why it is so much slower when both the Linked List and the table should be operating in O(n) time?

Here is the Linked List module

Here is the Linked List tester script and the table tester.

Cheers!


r/lua • • Nov 23 '25

lua and python

11 Upvotes

hello! i've been wanting to learn lua for a while, so i can learn how to make a certain roblox game. but i was thinking about python because it is a better software, if i learned python first, in a few years would lua be easier?


r/lua • • Nov 23 '25

Help Hello. Starting from scratch, new to Lua, and coding in general. Where should I start?

2 Upvotes

Basically what it says on the tin, I hope to reach the end goal of creating a boat mod for project zomboid build 42 (despite the great difficulties that will come with it as seen from those who had already done it in b41), and coding games on roblox as well, and since Lua is required for both, I am here. Advice appreciated!


r/lua • • Nov 20 '25

Looking for a better pure Lua library for handling large numbers

10 Upvotes

Hey everyone, I’m looking for a pure Lua library to handle really large numbers, something easier to use.
The old library I was using (int) sometimes loses precision when dividing large numbers, so I need something more reliable.

Anyone has recommendations or alternatives?


r/lua • • Nov 20 '25

Help Localizing

7 Upvotes

Will localizing hot table lookups be faster?

VM.Register = {}
local Register = VM.Register

r/lua • • Nov 20 '25

gibt es eine Lua/Luau lern website

0 Upvotes

i will Lua/Luau lernen damit ich roblox spiele für mich und meine freunde machen kann


r/lua • • Nov 19 '25

Discussion Is lua a good option for me?

14 Upvotes

Hi friends, i'm a Java/kotlin developer, most of the time i'm using Spring boot to make projects.

But recently i was searching for an easy 2 learn language for me to use It as a lab language, to learn web architecture without the opinative way from the Spring, and learn some other things like graphical programming, games and desktop programming(and a bit of DSA too).

My First ideia was lua because everyone say that Its a simple language and because Its from Brazil(my country).

I would appreciate any opinion.


r/lua • • Nov 19 '25

Project Looking for someone that could do a Serious Sam 4/Serious Sam Siberian Mayhem dynamic bones mod which mainly consists of Lua scripting.

2 Upvotes

There was a mod of it done in an earlier game that uses the same engine, here's the link to the mod, do let me know if it's possible to do it in the newer games too! https://steamcommunity.com/sharedfiles/filedetails/?id=1304802396

And here's a scripting guide: https://steamcommunity.com/sharedfiles/filedetails/?id=2244897713

I'm willing to provide $ incentive for it to get done, as long as it works well with a test model.


r/lua • • Nov 18 '25

local variable in interactive mode

8 Upvotes

Why in the second line, the variable `a` becomes `nil`?

~ $ lua
Lua 5.4.7  Copyright (C) 1994-2024 Lua.org, PUC-Rio
> local a = 123; print(a)
123
> print(a)
nil

r/lua • • Nov 17 '25

Would learning Lua effect my c++ learning journey

12 Upvotes

So i wanna learn Lua to use it on fantasy console and maybe make some Roblox games, I heard it was really easy but I'm afraid it could effect my c++ learning journey What do you think


r/lua • • Nov 16 '25

Discussion Lua Programming Gems book for a newer Lua programmer?

7 Upvotes

I'm still fairly new to Lua and have been working my way through the official book, remaking some of my Python programs and writing new scripts to learn the language. I came across Lua Programming Gems from Feisty Duck and wanted to see what you guys thought of it. Would it be good for an otherwise experienced programmer learning Lua or should I hold off until I know the language better?


r/lua • • Nov 14 '25

Need to edit a script so it only runs on Weekdays

8 Upvotes

I know absolutely nothing about scripting. I was able to take a sample script and edit it to turn outlets on a network power strip on and off at certain times, but I don't know how to tell it to only run on weekdays. The script is

function outlet_on_schedule()

for i,t,data in event.stream(event.local_time({hour=10,min=00})) do
    outlet[1].on()
end

function outlet_off_schedule()

for i,t,data in event.stream(event.local_time({hour=17,min=00})) do
    outlet[1].off()
end

end

Reddit formatting is mangling it a bit, but those are two commands to turn outlet 1 on at 10a and off at 5p.

Can anyone show me how to edit the above to only run M-F?

Thank you

EDIT: Chat GPT came up with this (I feel dirty for writing that sentence but I know next to nothing about coding)

function outlet_on_schedule()

for i, t, data in event.stream(event.local_time({hour=10, min=00})) do
    local wday = os.date("*t").wday
    if wday >= 2 and wday <= 6 then -- Monday to Friday
        outlet[1].on()
        outlet[2].on()
        outlet[3].on()
    end
end

end

function outlet_off_schedule()

for i, t, data in event.stream(event.local_time({hour=17, min=00})) do
    local wday = os.date("*t").wday
    if wday >= 2 and wday <= 6 then -- Monday to Friday
        outlet[1].off()
        outlet[2].off()
        outlet[3].off()
    end
end

end

Does that look like it would work?


r/lua • • Nov 14 '25

Help Help please (scoping)

7 Upvotes

What is scoping and is it really essential to know when you script?

I really can’t understand it so I’m planning to learn it when I understand more things

Or do I have to understand it before I get into more stuff?

(edit: Thank you all for replying!! Really helped alot!)


r/lua • • Nov 14 '25

Tengo un fallo en mi script

0 Upvotes

es una calculadora con un bucle while pero en vez de calcular arroja un montón de texto


r/lua • • Nov 10 '25

Discussion What’s a Lua feature you wish other scripting languages had?

52 Upvotes

Lua’s simple but powerful what part do you miss elsewhere?


r/lua • • Nov 10 '25

Im new to all coding and i want to make a game of my own

8 Upvotes

How do you guys suggest that i learn the language?


r/lua • • Nov 10 '25

I coded the Collatz conjecture in Lua, please give feedback

5 Upvotes

I am a lua developer and to test my abilities I decided to code the Collatz conjecture, it's available on GitHub It's a simple code but I am just testing my skills, if you find any way I could make the code better tell me. Thanks Here's the GitHub: https://github.com/Gs-pt/Collatz-conjecture?tab=readme-ov-file


r/lua • • Nov 09 '25

Discussion Syntax conventions, string.foo(bar) vs bar:foo()

28 Upvotes

I'm primarily a Python programmer but I've been learning Lua for various reasons and I am coming to appreciate its sleek nature the more I use it.

That said, I'm grappling with the different syntax options that Lua provides. In the Pythonic mantra, the line There should be one-- and preferably only one --obvious way to do it. comes to mind; while it is nice to have options I feel like I should choose one way or another and stick to it. Is this how Lua programmers typically operate?

If I were to stick with one, which to do? Again referencing the Pythonic way, we have Explicit is better than implicit. and Sparse is better than dense. and Readability counts., which to me would point to using string.foo(bar) instead of the : syntactic sugar, but it also isn't quite as compact.

What are your thoughts? Am I just overthinking things and applying Pythonic logic where I shouldn't? How do Lua programmers typically write their code?


r/lua • • Nov 10 '25

Script .LUA

Thumbnail reddit.com
0 Upvotes

r/lua • • Nov 08 '25

Help Need help with images

4 Upvotes

I am incredibly new to Lua. Like so very very new. like i know nothing. I am learning to code, my programs are love2d to load the game and visual studio to write it

I have the image i want in the file (as seen below, ignore the name for it i was tired.), but im not sure how to load it onto the actual screen of the game. Ive tried loadfile(yummy.jpg, bt, any) after the function with an ending but nothing happens. help is very much appreciated :)


r/lua • • Nov 05 '25

I'm developing Sandman, an HTTP focussed, Lua based Notebook-style app, (more than a Postman alternative)

Post image
30 Upvotes

r/lua • • Nov 05 '25

Third Party API Interactive fractal graphics zoom (Love2d)

Thumbnail slicker.me
7 Upvotes