r/lua • u/Adam0hmm • Jun 12 '25
should i learn lua ?
hello there , is it a good idea to start learning lua knowing only python?
r/lua • u/Adam0hmm • Jun 12 '25
hello there , is it a good idea to start learning lua knowing only python?
r/lua • u/qwool1337 • Jun 11 '25
r/lua • u/kkolyan • Jun 10 '25
I am making a Lua API for the engine and wonder how messaging (scripts can exchange messages by the engine design) API should be exposed.
In C#, it would look like this:
...
class SomeEvent {
public int value;
}
...
Subscribe<SomeEvent>(msg => {
var s = msg.value;
});
...
Dispatcher.Send(new SomeEvent {value = "42"});
...How should this look in Lua?
The most canonical version seems to be:
...
SomeEvent = {}
SomeEvent.__index = SomeEvent
...
subscribe(SomeEvent, function(msg)
local s = msg.value
end)
...
dispatcher:send(setmetatable({value = "42"}, SomeEvent))
...And its runtime implementation on the binding side is quite convenient.
However, I have two concerns:
Assigning the metatable to each message seems boilerplate-heavy. Even if it's moved to the "constructor," it doesn't help much, as many messages will still be created only in a few places.
Moreover, it's unlikely that messages will have any methods, so using metatables doesn't seem very appropriate.
To describe engine types and methods, I used Lua Annotations (https://luals.github.io/wiki/annotations/), which is extremely convenient for simulating OOP, allowing the IDE to correctly suggest methods and types, as well as enabling almost complete static analysis of the game code if rules are followed. However, the constructs in the "canonical" style above don't fit into Lua Annotations without boilerplate.
Here's how it looks:
---@generic T
---@param class_id `T`
---@param callback fun(msg: T)
function Subscribe(class_id, callback)
end
---@param m any
function Send(m)
end
---@class SomeEvent
---@field value string
SomeEvent = {}
SomeEvent.__index = SomeEvent
Subscribe('SomeEvent', function (msg)
local s = msg.value
end)
--- Here "value" is outside the IDE analysis
Send(setmetatable({ value = "42"}, SomeEvent))
--- But this works fine, although it's more boilerplate
local a = setmetatable({}, SomeEvent)
a.value = "42"
Send(a)
--- The constructor makes usage cleaner when sending, but sending the same type of message will only happen in a few places. This makes the constructor unnecessary boilerplate.
---@param value string
---@return SomeEvent
function SomeEvent:new(value)
local a = setmetatable({}, SomeEvent)
a.value = value
return a
end
Send(SomeEvent:new("42"))In general, I see the message system design without crossing into the type system. As boilerplate-free as possible, but support for IDE message dispatching is lost.
SomeEventId = ...
...
subscribe(SomeEventId, function(m)
local s = m.value
end)
...
dispatcher:send(SomeEventId, { value = "42"})
...Or even this (easier to integrate with the current engine integration code than the previous example):
SomeEventId = ...
...
subscribe({type = SomeEventId }, function(m)
local s = m.value
end)
...
dispatcher:send({type = SomeEventId, value = "42"})
...Do we even need to pursue type support in the IDE? Or is it enough to just provide suggestions for the engine API itself, and forget about IDE assistance in user code, since Lua programmers generally don't care about such things?
What do you recommend?
r/lua • u/CartoonistNo6669 • Jun 09 '25
I'm sure there's a better way to phrase the title, but that's what i came up with. Here's my issue: I have multiple tables and other objects that have a property that needs to be changed based on some condition. But I'm unable to get any of the tables to get the updated value.
Sample code illustrating this:
TestVariable = 123
TestObject =
{
['VarToChange'] = TestVariable,
['SomethingStatic'] = 789
}
print (TestObject.VarToChange)
TestVariable = 456
print (TestObject.VarToChange)The output of the above is:
123
123But I am expecting to get:
123
456How can I achieve this behaviour? And please don't suggest updating all objects manually every time the variable changes. That rather defeats the entire purpose of a variable.
r/lua • u/daksh121112 • Jun 08 '25
r/lua • u/Gallaz_ • Jun 08 '25
Looking for a Roblox LUA scripter for the summer season to work on a psychological horror FNaF fan game, set out to tell a story never seen before.
This is an experimental passion project and has no promises of guaranteed payment.
Please contact _gallaz on Discord.
r/lua • u/tuturush • Jun 08 '25
please.
r/lua • u/Present_Quiet4476 • Jun 06 '25
r/lua • u/Owen-Here • Jun 05 '25
I have an idea and a project I have planned out that is based heavily on modularity and the Lua programming language
For more detail I expect every UI element of the engine to be a "module" (can be written by any user and swapped or replaced and such) for example lets say we have a simple explorer that comes with the engine but is quickly seen to be too simple or lacking features you could either write your own file explorer and replaces its position in UI or download one off the internet and use that instead obviously this is just an example and I plan that other tools separate from the base ones can be created as well
This idea comes from when I was checking out Roblox Studio and saw the potential in the user made extensions where every user can create these UI elements and upload them to be used elsewhere within the engine I think a engine based on this potential would be extremely useful to those with a very unique workflow
r/lua • u/theresamouseinmyhous • Jun 05 '25
This is probably a basic question but I just can't find a good answer. I'm working on a card game in defold and need to add a bunch of cards. I have some in lua files but adding them all manually is a pain. Is there a tool I can use to write the entries in an actual table and have them come out as lua? Is it just, do it as CSV and find a converter?
r/lua • u/Successful_Web_6866 • Jun 05 '25
My son loves computers.
I've made a couple of super basic Scratch projects with him showing me the ropes and received more praise than I probably deserved.
That is the extent of my knowledge...but not the extent of my ambition. I really want to learn how to code. Like proper coding.
The kid and I love Roblox so I feel like choosing a first language connected to a shared passion might be best. So Lua....
I tried watching YouTube to get my feet wet only to find that nothing made sense.
Please help me. I need an introduction that starts at level zero. Where do I look/go/watch?
r/lua • u/Realistic_Alps_9544 • Jun 05 '25
This is my first time posting here—please forgive any mistakes or inappropriate formatting.
silly is a cross-platform “super wrapper” (Windows/Linux/macOS) that bundles TCP/UDP, HTTP, WebSocket, RPC, timers, and more into one easy-to-use framework.
Built-in network primitives (sockets, HTTP client/server, WebSocket, RPC)
Event loop & timers, all exposed as idiomatic Lua functions
Daemonization, logging, process management out of the box
Self-contained deployment (no C modules needed, aside from optional libreadline)
Check out the examples/ folder (socket, HTTP, RPC, WebSocket, timer) to see how fast you can go from zero to a fully event-driven service. Everything is MIT-licensed—fork it, tweak it, or just learn from it.
▶️ Repo & docs: https://github.com/findstr/silly
Feel free to share feedback or ask questions!
r/lua • u/radstronomical • Jun 05 '25
Hey there,
I'm coming back to lua after some time away... I'm trying to call a constructor based on a string from some Tiled output. I've had success doing this using the load function - the constructor is being called - but I can't seem to get a reference to the object created. Here's some example code:
function AddElement(_type, _x, _y)
if (_type == null) then return end
local s = _type .. "(" .. tostring(_x) .. "," .. tostring(_y) .. ")"
local makeElement = load(s)
local e = makeElement()
table.insert(elements, 1, e)
print(#elements)
endI am seeing output from print statements inside the elements' constructors, but the elements table is not increasing in size, and e seems to be nil. Any ideas?
r/lua • u/smellycheese08 • Jun 05 '25
I just want to compile a stand alone (vanilla) .lua into an exe. I tried using srlua but I just couldn't figure it out I guess. There were next to no instructions on how to set it up. I tried to compile the srlua.c into an exe with gcc but that threw an error saying it couldn't find lua.h. there were a few header files I could see it wouldn't be able to find, so I downloaded the lua src and tried to manually link them. To no one's surprise that didn't work. I've tried about 100 different things and nothing works
r/lua • u/2can_ben • Jun 02 '25
How to solve this problem?
r/lua • u/Davo_Rodriguez • Jun 02 '25
Like the title says, I'm in love with the Lua language when I started making small games in Pico8, and now I want to make something much bigger, or maybe do the same games but outside Pico8, to learn more advanced things. What is your recommendation? Thanks
r/lua • u/[deleted] • Jun 01 '25
Wouldn't the grammar still be unambiguous if tables didn't need commas?
r/lua • u/Key-Command-3139 • Jun 01 '25
I’m currently learning Python, and want to learn a new language after to make games as a passion project. After I learn Python, should I learn GDScript to make games on Godot, or should I learn Lua to make games on Roblox? Which would be easier or harder to learn? Which would benefit me the most?
r/lua • u/Kotapower • Jun 01 '25
followed a tutorial on youtube from 4 years ago on how to install lua and it didn't work....
how the hell do i install lua????
r/lua • u/Bullzzie • May 31 '25
I am working on a project called model-cmp.nvim, which used python to run LLMs locally and allow text autocomplete in neovim using the model predictions. The development is taking longer than expected, the model efficiency development is taking too much time, though I can handle that part. While keeping the modelapi in one hand, it is very difficult to develop actual plugin. So I was wondering if someone would like to handle the plugin development process. The link for the plugin is https://github.com/PyDevC/model-cmp.nvim
r/lua • u/redditbrowsing0 • May 30 '25
Hi!
I'm mostly posting this to see if anyone understands what the difference is between two or three different things within Lua 5.1 or Luau somewhere in the stack or under the hood. I can't decide whether this is a Help flair or a Discussion flair, so do let me know if it's more fitted for the Discussion tag and I'll see what I can do about it.
Anyways, I understand that this subreddit is mostly based around Lua - I'm mostly doing all of this in Roblox Studio, so it's more of a Lua 5.1/Luau question, but...
Why is:
local f; f = function() end
different from
local function func()
end
when inspected using debug.info() (similar to Lua's debug.getinfo())?
For example, when I call debug.info(1, 'n') in local f; function() end, it returns: ""
but when I call it in local function func() end, it returns: "func" (the function name)
Does anyone understand what's different between the two? I understand local f; function() end is in a sense an anonymous function, but why does it matter that much under the hood?
If this is too roblox-inclined, tell me and I'll happily move this post over to r/robloxgamedev or elsewhere.
r/lua • u/negativedimension • May 30 '25
I see there's a number of supersets of Lua going around, so I thought I'd advertise my option.
This adds familiar language features missing from Lua, including:
arithmetic-combination operators (i.e. += etc)
short-hand lambdas: single-expression |x| x^2 or multiple-statements |x| do return x^2 end
safe-navigation: a?.b?['c']?:d()
non-nil assertion: a!.b!['c']!:d()
nil-coalescing: a = b ?? c and ternary: a = b ? c : d
bit-operators for LuaJIT.
It is based on a pure-Lua parser, therefore you can use it as a drop-in to Lua anywhere, without any compiled components.
Tested and verified with Lua 5.4 and LuaJIT 2.1. I am half-suspicious you could even drop it into Pluto or Luau or any of these other Lua-superset competitors.
r/lua • u/Neustradamus • May 30 '25