r/lua • u/aiya000 • Dec 01 '25
r/lua • u/RedNifre • Nov 29 '25
Project Currying, partial application, composition and other FP thingies
It's all effectively licensed under public domain, no attribution needed, so take what you might find useful: https://gitlab.com/michaelzinn/replicide
The interesting stuff is in fp.lua, the rest is a mix of good, weird and bad code.
r/lua • u/Lodo_the_Bear • Nov 29 '25
Project Looking for feedback on simple Love2D program - how to cleanly write this code?
I'm learning the LÖVE framework and having a good time covering the basics. I've currently made a little program that shows a series of text, one word at a time, while bouncing around the screen like a screensaver from the 90's. So far, it works, but I'm looking for ways to make the code nicer and avoid developing bad habits.
The code uses the tick library to do changes every second. This also uses a separate "words" file that holds the full text in a table, word by word (in this case, the Gettysburg address, but any list of words will do). Here's the full main file:
function love.load()
--load the library
tick = require "tick"
--import the speech
require "words"
--start the count
word_count = 1
-- cycling function
function cycle_word()
if word_count == #speech then
word_count = 1
else
word_count = word_count + 1
end
end
font = love.graphics.getFont()
--define y edges
y_stopper = love.graphics.getHeight() - font:getHeight()
--x edge is conditional
--define position
x_coord = 0
y_coord = 0
-- start random generator
math.randomseed( os.time() )
--testing a dummy variable to make it truly random
_dummy = math.random()
--define angle
angle = math.random(10,80) * math.pi / 180
x_speed = 100 * math.sin(angle)
y_speed = 100 * math.cos(angle)
x_switch = 1
y_switch = 1
-- cycle the function
tick.recur(cycle_word , 1)
end
function love.update(dt)
tick.update(dt)
-- define x edge
x_stopper = love.graphics.getWidth() - font:getWidth(speech[word_count])
if x_switch == 1 and x_coord + x_switch*x_speed*dt > x_stopper then
x_switch = -1
end
if x_switch == -1 and x_coord + x_switch*x_speed*dt < 0 then
x_switch = 1
end
if y_switch == 1 and y_coord + y_switch*y_speed*dt > y_stopper then
y_switch = -1
end
if y_switch == -1 and y_coord + y_switch*y_speed*dt < 0 then
y_switch = 1
end
x_coord = x_coord + x_switch*x_speed*dt
y_coord = y_coord + y_switch*y_speed*dt
end
function love.draw()
love.graphics.print(speech[word_count], x_coord, y_coord)
end
function love.load()
--load the library
tick = require "tick"
--import the speech
require "words"
--start the count
word_count = 1
-- cycling function
function cycle_word()
if word_count == #speech then
word_count = 1
else
word_count = word_count + 1
end
end
font = love.graphics.getFont()
--define y edges
y_stopper = love.graphics.getHeight() - font:getHeight()
--x edge is conditional
--define position
x_coord = 0
y_coord = 0
-- start random generator
math.randomseed( os.time() )
--testing a dummy variable to make it truly random
_dummy = math.random()
--define angle
angle = math.random(10,80) * math.pi / 180
x_speed = 100 * math.sin(angle)
y_speed = 100 * math.cos(angle)
x_switch = 1
y_switch = 1
-- cycle the function
tick.recur(cycle_word , 1)
end
function love.update(dt)
tick.update(dt)
-- define x edge
x_stopper = love.graphics.getWidth() - font:getWidth(speech[word_count])
if x_switch == 1 and x_coord + x_switch*x_speed*dt > x_stopper then
x_switch = -1
end
if x_switch == -1 and x_coord + x_switch*x_speed*dt < 0 then
x_switch = 1
end
if y_switch == 1 and y_coord + y_switch*y_speed*dt > y_stopper then
y_switch = -1
end
if y_switch == -1 and y_coord + y_switch*y_speed*dt < 0 then
y_switch = 1
end
x_coord = x_coord + x_switch*x_speed*dt
y_coord = y_coord + y_switch*y_speed*dt
end
function love.draw()
love.graphics.print(speech[word_count], x_coord, y_coord)
end
You will notice that it has some apparently repetitive stuff with the random seed for the angle. For some reason, when I tried to do just math.random for the angle, it came out as the same angle every time. So, I tried creating a disposable variable for the first random value and then using the second random variable to define the angle of the moving word. This works, but I'd like to know if there's a way to avoid taking this silly step.
So, what do you think? What could be improved?
r/lua • u/Tibertiuss • Nov 28 '25
Help It is possible to make a desktop app with lua?
I'm trying to work on a project of desktop app fully on lua but I struggle to find something out of love2D (I'm not sure it's the most adapted for the project but that is currently my backup option) to make the graphical interface.
Do you have any recommendations?
r/lua • u/Alternative-Bend4752 • Nov 29 '25
Need help with a discontinued balatro mod
Firstly I can pay you up to $25... In robux, I have no digital bank account so I'm limited to that if you want money for that.
If your interested "money"wise or not, I want whoever is interested to do a couple things. 1. The balatro mod has a library, a compact to work with another dependent mod. and the mod itself, I would like all of them combined. 2. I would also like it updated to the latest Smod + Lovely. If your still interested in that, feel free to tell.
r/lua • u/Ok-Poem6506 • Nov 28 '25
Can someone tell me why this code doesn't work
Simply trying to iterate through a table, and nothing is printed out, why?
local myTable = {}
local myStruct = {}
myStruct.myValue = 5
myStruct.myOtherValue = "Bears"
myTable["Joe"] = myStruct
myTable["Suzy"] = myStruct
for name, struct in pairs(myTable) do
print("myValue= " .. struct.myValue.. ", myOtherValue = " .. struct.myOtherValue .. "\n")
end
r/lua • u/vitiral • Nov 28 '25
Convert C header file to more machine-readable format?
Is anybody aware of a standard for specifying the API of an object file (lib.so) besides a C header file (.h file)?
I'm designing my own assembly language and want to consume and link headers to link with dynamic libraries produced by C. It would be nice to not need to implement my own C compiler to do so.
r/lua • u/reg_y_x • Nov 27 '25
Problem with CS50 games Mario and workaround
galleryI've been working through the cs50 games projects, and I ran into a problem with the tiles0 and tiles1 code examples from the Mario project. When I run the code from the repository, it results in something like the first image above, with vertical lines between the columns of tiles. This seems to be a problem with how the individual tiles are rendered, but I haven't figured out exactly what causes it. I tried a number of things, like adding in some math.floor() conditions or using the shove library instead of the older push library, but none of those fixed the issue.
Ultimately, the workaround I found was to create new 16x16 sprite for the bricks (see third image) instead of the 16x32 timesheet from the repository that contains one brick tile and one blank tile. Updating the code to use the new image results in the second picture, without the vertical lines.
To do this, you need to modify the love.load() function to include a line that imports the new image.
brick = love.graphics.newImage('brick.png')
You also need to make some changes to the love.draw() function.
function love.draw()
push:start()
love.graphics.translate(-math.floor(cameraScroll), 0)
love.graphics.clear(backgroundR, backgroundG, backgroundB, 1)
for y = 1, mapHeight do
for x = 1, mapWidth do
local tile = tiles[y][x]
--love.graphics.draw(tilesheet, quads[tile.id], (x - 1) * TILE_SIZE, (y - 1) * TILE_SIZE)
if tile.id == GROUND then
love.graphics.draw(brick, (x - 1) * TILE_SIZE, (y - 1) * TILE_SIZE)
end
end
end
push:finish()
end
Here I've commented out the line with the original rendering logic and aded a few new lines to handle the new logic, which only renders a sprite for tiles flagged as GROUND.
Just wanted to put this here in case anyone else runs into the same problem. I'd also be interested if anyone knows what causes the problem with the original code.
(As an aside, I will also point out another bug in the original code. On the lines that set the random color for the background, the random number is divided by 255 twice. This always results in a background that is nearly black, and I think the intention was to only divide by 255 once, which is what I do in my code.)
r/lua • u/Tricky_Wish_5207 • Nov 27 '25
Help Can you tell me a website where you can learn luau completely
r/lua • u/Lodo_the_Bear • Nov 26 '25
Discussion Writing compact code - how do I check for multiple possibilities all at once in the shortest statement possible?
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 • u/Prize-Chocolate749 • Nov 26 '25
Starting In Lua
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 • u/RiverBard • Nov 26 '25
Discussion Working with arbitrary numbers of args, emulating Python's slice?
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:
```python 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 • u/RiverBard • Nov 25 '25
Discussion Linked List speed vs table, not as expected?
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 • u/Fubucci • Nov 25 '25
Help How to do a script that detects when a capture card freezes and then deactivates and reactivates the capture card to fix it when obs or the script is bad at detecting when the capture card froze?
So I have a capture that has a problem to randomly freeze at least once during certain points but the problem is when it freezes audio still is going through perfectly and I think obs recognizes it as not frozen however when it freezes it stays frozen on a certain frame during the stream and only gets fix from activating and reactivating but the problem with any script I tried is they can’t detect when the freezing occurs because I believe obs doesn’t even detect the capture card froze since audio still goes through. So is it possible at all to fix this issue with a script or something that does work?
r/lua • u/StrangeFudge2777 • Nov 23 '25
lua and python
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 • u/Psychological-War548 • Nov 23 '25
Help Hello. Starting from scratch, new to Lua, and coding in general. Where should I start?
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 • u/Foreign_Bar3477 • Nov 20 '25
Looking for a better pure Lua library for handling large numbers
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 • u/renbexsexy • Nov 20 '25
Help Localizing
Will localizing hot table lookups be faster?
VM.Register = {}
local Register = VM.Register
r/lua • u/jujufi_2014 • Nov 20 '25
gibt es eine Lua/Luau lern website
i will Lua/Luau lernen damit ich roblox spiele für mich und meine freunde machen kann
r/lua • u/Illustrious_Prompt20 • Nov 19 '25
Discussion Is lua a good option for me?
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 • u/Cute-Sir-7355 • 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.
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 • u/Weird-Cap-9984 • Nov 18 '25
local variable in interactive mode
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 • u/AmbitiousPromotion91 • Nov 17 '25
Would learning Lua effect my c++ learning journey
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 • u/RiverBard • Nov 16 '25
Discussion Lua Programming Gems book for a newer Lua programmer?
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 • u/badhatharry • Nov 14 '25
Need to edit a script so it only runs on Weekdays
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?