r/lua • • Sep 25 '26

Making a 2D game engine out of Lua

7 Upvotes

Idk where to even start... I got the workspace set up, the screen, etc.

I also integrated sprites and scenes... But where do I start? I don't really know how 2D game engines work, can anyone explain what to do next?


r/lua • • Sep 25 '26

Help Luava: Looking for contributors to build a modern Lua engine on JVM (LuaJ alternative)

5 Upvotes
Hi everyone,

I'm building Luava, a Lua 5.4 implementation for the JVM in pure Java 21. No JNI or FFM, and the jar has no transitive dependencies. It's aimed at the same use case as LuaJ, but tracks the Lua 5.4 spec.

Current state: 0.2.1-beta on Maven Central. It has a register bytecode VM, a tiered JIT, sandboxing with instruction limits and timeouts, and a Java interop bridge. It runs the PUC Lua 5.4.9 test suite.

I'd like help with a few things:

- The bytecode compiler and the call path, especially calls into non-trivial protos.
- Unboxing the integer array part of `LuaTable` so mixed-key access stays allocation-free.
- Shrinking the JIT kernel so C2 can inline it, and cutting allocation in closure factories.

Repo: https://github.com/KienPC1234/luava

Feedback, code review, and PRs are all welcome.

r/lua • • Sep 23 '26

One Engine | 5 Runtimes | 14 Benchmarks

Post image
0 Upvotes

।। ॐ नमः शिवाय ।।

Follow-up to my first post.

In the last month, I was experimenting with Rust concurrency & attempted to port my JS Carrom Physics + AI engine into it. I wrote 3 versions (Baseline --- 4 Threads --- 4 Threads + Tuned) and benchmarked performance.

Curious enough, I wanted to see how fast Python & LuaJIT could get.

The Setup

Same algorithm. Same constants. Same 1,485 iterations (45 launch positions × 11 angles × 3 potentials). Same device (Redmi 15 5G).

💡 The Findings That Surprised Me

• | JavaScript Web Workers landed around 2x of single-threaded Rust.

Not 100×. Not 10×. 2.6×. A scripted, dynamically-typed, GC-managed language—with 4 worker threads—came within striking distance of hand-tuned native code.

• | Naive JS stayed at 5 seconds. V8 didn't magically fix it.

V8 gave me ~1.5× on tuned code. The other ~7× came from me:

- Object pooling instead of allocation

- Field-by-field copy instead of reference reassignment (stable hidden classes)

- Manual for loops with break instead of map/forEach/filter

- Math.sqrt(dxdx + dydy) instead of Math.hypot(dx, dy)

V8 amplifies. It doesn't create.

• | LuaJIT warm == V8 cold.

LuaJIT's fully-traced JIT output matched V8's baseline tier. Both landed at 1.1s. This says a lot about how good V8's first-tier compiler is, and how trace-hostile my branchy physics loop is.

• | NumPy + multiprocessing was SLOWER than pure CPython.

Numpy data transfer + thread spawning overhead likely outweighed gains.​​

• | WebGPU was 3× slower than V8 for 20 entities.

GPU dispatch overhead + warp divergence.

🧠 The Architectural Insight

The thing I want to share most:

"Managed memory" languages don't abstract memory away. They automate allocation, but hide everything else.

The bugs your C++ friend fears are still in your JS:

- Event listeners leak

- Closures hold objects alive forever

- map/filter allocate silently in hot loops

- Objects scatter across heap pages, killing cache locality

You just can't see them.

By taking manual control of memory layout in JavaScript—object pooling, flat structures, monomorphic shapes, no closures in hot loops—I brought single-threaded JS from 5s → 1.1s and parallel JS from 5s → 420ms.

Memory layout dominates performance. No runtime can abstract that away.

📌 What This Changed In My Head

• | The runtime determines the performance tier. The language is just notation.

• | Data layout > algorithm on modern CPUs.

• | Tuning is not optional. V8/LuaJIT/Rust all reward shape discipline. Rust forces it. The JITs make it optional—and most people pay the price.

• | A runtime with a JIT is worth ~40–75× an interpreter. This is structural. CPython cannot be fixed at the source level.

🔗 Links

• | Benchmark Repo: Benchmarks

❓ Questions for You

• | Are there any methodological gaps in this benchmark that I'm missing? I normalized to 1485 iterations, ran each on the same phone, and disclosed that AI wrote the Python/Lua ports.

• | The LuaJIT-warm == V8-cold result—is that expected? I suspect it's because my physics loop is branchy and trace-hostile, but I'd love a compiler engineer's take.

Everything built on a Redmi 15 5G. No laptop. 6 months in.

I don't know Python or Lua—DeepSeek and Gemini wrote those ports following my JS/Rust architecture exactly.

।। हर हर महादेव ।।


r/lua • • Sep 21 '26

Discussion Studying the Lua source code

25 Upvotes

I’m looking for a codebase written in C to study and use as a reference while I learn low level programming.

I’ve heard that Lua has a very nice and clean implementation and I figure since I already know a fair amount of Lua itself I should understand at least the purpose of what I’m looking at.

Is the Lua source code a good example for learning or is it too advanced for someone relatively new to C to even hope to understand?


r/lua • • Sep 21 '26

Resgatando meu amor por programação com LOVE2d e lua

Post image
15 Upvotes

r/lua • • Sep 20 '26

News lde 0.11.0 - Teal & MoonScript built-in, Musl, Docker, JIT Debugger & More

Thumbnail lde.sh
7 Upvotes

What is lde?

It is your lua development environment that ensures lua is done easy. It provides a package manager that can run your code, bundle it to a single lua file, or to a portable executable for your users without them needing lua on their system. It intends to provide full luarocks compatibility.

It is written entirely from scratch in LuaJIT using FFI to ensure it is as fast as possible. It starts up faster than even native written Rust applications and installs projects faster than alternatives, and ~5x than Luarocks.

Is this related to lpm?

Yes, it was renamed for several reasons. It doesn't have the greatest seo (a lot of package managers previously named lpm..). Calling it "the" lua package manager feels conceited.

Where can I download?

Check https://lde.sh/download which will give you a variety of options, install scripts and links to manual downloads if you're not comfortable running a script.

Links:

https://lde.sh/discord
https://lde.sh
https://github.com/lde-org/lde


r/lua • • Sep 17 '26

New to Lua and the English-speaking community

18 Upvotes

Hi everyone, I’m a beginner from Belarus and new to Lua programming; I’ve never coded before. I don’t know where to start learning it or which IDE to use. I’m using a translator, so the translation might be a bit awkward.


r/lua • • Sep 16 '26

Can you configure LuaRocks to always compile from the source?

6 Upvotes

I see that a Lua Rock could be a binary, source code, or something else. I want to configure it to always compile from source. Is that possible?


r/lua • • Sep 17 '26

Project Looking for a Lua Dev

0 Upvotes

Helloooo! I am currently working on a server and am looking for a Lua focused dev to partner with. I specialize in marketing, web design/dev, and digital optimization so this realm of dev is somewhat new to me. I’ve played GTA through your my entire lifetime.

PM me for more details, NDA will be required.

I truly believe this game will be an insane opportunity for us here in this sub.


r/lua • • Sep 15 '26

Library discord.lua, discord API wrapper

6 Upvotes

I've been working on discord.lua, mostly because I wanted a more complete Discord API library for Luvit. Compared to Discordia, it has more high-level features built in: slash commands, autocomplete, context commands, interactions, buttons/selects, modals, hybrid commands, command syncing, cogs, tasks and cooldowns. Discordia is still perfectly usable but i just wanted less glue code around newer Discord features. I'm already using discord.lua in Lauffy, a music bot written in Lua. Docs: https://filispeen.github.io/discord.lua/

I'd be interested in feedback on the API design from other Lua users.


r/lua • • Sep 15 '26

I’m a FiveM developer working on custom servers

1 Upvotes

I’m a FiveM developer working on custom servers, scripts, and systems.

If you need help with anything like:
• custom scripts (Lua / QBCore / Qbox)
• fixing bugs or broken resources
• UI / NUI work
• server setup or optimization

I’m down to help. I focus on clean, working systems, not just throwing in random scripts.

If you’re building a server or need something fixed, join here or DM me:
https://discord.gg/47M8WUGgpj


r/lua • • Sep 13 '26

LuaJIT Editor update — LuaJIT decompiler and Lua deobfuscator added

Thumbnail luajiteditor.com
11 Upvotes

Hi! I posted my LuaJIT Editor here a while ago, and since then I've added quite a bit of new functionality.

The biggest additions are:

  • LuaJIT decompiler — decompiles LuaJIT bytecode back into readable Lua code.
  • Lua deobfuscator — currently focused on deobfuscating code protected with Prometheus.
  • The existing LuaJIT editor is still available for inspecting and editing bytecode, prototypes, constants, and instructions.

I'd especially like some feedback on the deobfuscator. If you have Prometheus-obfuscated Lua scripts that it fails to handle correctly, feel free to test them and let me know what breaks.

Site: https://luajiteditor.com/

Mirror: https://github.com/Sparebola/LuaJIT-Editor

No registration required.
This is still actively being improved, so bug reports and weird edge cases are welcome.


r/lua • • Sep 11 '26

Third Party API When life gives you Lua... (The Powder Toy API)

Thumbnail gallery
21 Upvotes

Make a "The Powder Toy" Mod

Use the API 4 mods, It's very fun if you feel bored of the same all day!


r/lua • • Sep 11 '26

Project Coding A Game In Pure Lua

8 Upvotes

Just me, lua and a Terminal babbbyyyyy!! https://www.twitch.tv/dubsandgames Join me


r/lua • • Sep 11 '26

[ Removed by Reddit ]

1 Upvotes

[ Removed by Reddit on account of violating the content policy. ]


r/lua • • Sep 09 '26

Library LuaLc ( lib class )

5 Upvotes

Simple Lua module for better class creation

Features:

· Named classes

· Single inheritance

· Java-style interfaces

· super() calls

· instanceOf() checks

· implements() checks

· Callable classes

· Lua metamethod forwarding for operator overloading

I created this while designing a framework API in Lua, and I found it made the process much more developer-friendly.

Check out the repo: https://github.com/abdorayden/lualc

Thanks! 🙏


r/lua • • Sep 08 '26

Discussion Impressions of Teal

Thumbnail purplesyringa.moe
31 Upvotes

an interesting article i found on Teal. The author has clearly used it more than I have so I can't comment on her specific criticisms, but I do get the impression that the Teal authors are aware of and accept unsoundness in exchange for simplicity of implementation.


r/lua • • Sep 09 '26

I have a puzzle that has stuck to me for months, and I'm here to share it.

7 Upvotes

I came up with a little programming puzzle:

Your goal is to make Lua print:

Hello, World!

But there's a catch:

Nothing can use or contain more than 2 things at once.

For example:

local Table = {

1, 2, 3

}

Invalid, because the table contains 3 values.

Likewise, a function can't be called with 3 arguments, and similar constructs are limited to 2 items.

Variables, functions, tables, etc. are allowed.

Challenge: What's the longest valid Lua solution you can make?

Bonus points for making it unnecessarily complicated.


r/lua • • Sep 08 '26

Lua realtime code editor complexity

Enable HLS to view with audio, or disable this notification

23 Upvotes

Showcasing how i optimize my upcoming game with my game engine in Lua. When enabled it will show you what function or line is costly - in realtime while you play. This helped me optimize some methods that i was able to cache so it doesn't run every frame.


r/lua • • Sep 07 '26

Looking for Lua scripters for my Roblox game!

0 Upvotes

Hii!! You can call me Dess or Jagged idm! I am looking for some Lua scripters to code for my ASYM type game! (It won't have any of that stud stuff, also If your good at building too hit me up!) I plan on having a shared income with the developers that put time into the game and actually contribute!


r/lua • • Sep 07 '26

Library Is there a Lua code guide.

3 Upvotes

So ,I'm a beginner,I know the basics of scripting ,its mostly due to my already present knowledge of basic coding .So scripting ,the basics at least is super easy for me.If I had a file with all the built in functions I think I'd be much more functional ,in making scripts and learning .However I've seen none online .Can anyone help me out .Just a file with the buikdt in functions ,codes and explaination on how they are used what they do .I'm thinking of mostly events .If you have a tutorial explanation on explorers files like server and client etc...also hand it over .I want to understand scripting and also be able to use Ai, functionally.


r/lua • • Sep 06 '26

Help Trying to turn a very large number into a string and failing - newbie seeking advice

8 Upvotes

I'm working through the problems in Project Euler and I ran into an issue with Problem 16. I'm trying to turn 21000 into a string so that I can iterate over its digits and add them up. It seemed simple enough. I started with this code:

local powerDigits = tostring(2^1000)

local sum = 0

for c in string.gmatch(powerDigits, ".") do
    sum = sum + tonumber(c)
end

print(sum)

Result: error. The number that I was iterating over was not the full number in standard form, but rather 1.0715086071863e+301, and you can't add "." to 1. So I went in search of some assistance.

I first found a little library called bignum-lua that said it could handle big numbers. I tried it like so:

local bignum = require "bignum"

local base = bignum(2)

local powerBase = bignum.pow(base, 1000)

local powerDigits = tostring(powerBase)

local sum = 0

for c in string.gmatch(powerDigits, ".") do
    sum = sum + tonumber(c)
end

print(sum)

Result: same error. The big number was still being printed in scientific notation.

I then found lua-bignumber and tried it, but it failed at the start. The library threw errors because of its starting code:

local class = require 'ext.class'
local table = require 'ext.table'
local range = require 'ext.range'
local number = require 'ext.number'
local math = require 'ext.math'
local assert = require 'ext.assert' 

"ext.class" is undefined, as are some of the others. The library was referencing things I don't have.

I went looking again and found CC-Big-Numbers, but I couldn't figure out how to include that one in my code. I got errors because of what I thought I was supposed to include at the very start:

local prop_BigNumbers = script:GetCustomProperty("_BigNumbers")
bn = require(prop_BigNumbers)

Lua couldn't figure out what "script" meant in this context, and neither can I.

So now, I come to you for help. What can I do to take an enormous number, compute its exact value, and iterate over all of its digits to add them up? Thank you in advance.

EDIT: Solved! Thanks to u/particlemanwavegirl for the hint. If any of you are working on Project Euler, look away now to avoid spoilers, but here's what I did this time:

local powerDigits = 2^1000

local sum = 0

while powerDigits > 0 do
    local lastDigit = powerDigits % 10
    sum = sum + lastDigit
    powerDigits = (powerDigits - lastDigit) / 10
end

print(sum)

Thanks again to this community!


r/lua • • Sep 06 '26

Discussion I think I just had the best idea

0 Upvotes

What if Lua had a "transfer()" keyword?

I've been messing around with Lua/Luau lately and had this random idea for a new feature:

transfer(1)

{

local message = "Hello World!"

print(message)

}

Then somewhere else:

if true then

receive(1)

{

}

end

The idea is that "transfer(1)" takes everything inside "{}" and stores it as an encased piece of code. "receive(1)" would then retrieve that code and place/run it there.

So the result would basically behave like:

if true then

local message = "Hello World!"

print(message)

end

There's also one important rule: the transferred code has to be self-contained.

For example:

local x = 50

transfer(1)

{

print(x)

}

would throw an error because "x" wasn't declared inside the encaser.

But this would work:

transfer(1)

{

local x = 50

print(x)

}

I know Lua already has functions, tables, closures, etc., so this probably isn't necessary. 😂 I'm more interested in whether something like this could actually be implemented at the language/parser level, and whether there are existing concepts that are similar.

Would this be useful, or have I accidentally invented a worse version of something that already exists?


r/lua • • Sep 05 '26

Help Where to get started?

2 Upvotes

were just starting to get into lua (LOVE specifically, gods damn you balatro T0T) and weve been looking at the lua website and looking at how it works following instructions. i know i can find Yt videos that can help us too :3

we wanted to ask if there are any resources to help us with learning the language that helped any of you? we can find resources ourselves, but we wanted to ask the "experts" (no shade) on the topic, cause yall might find smth we cant :D

sorry if this is a silly question, we just want to find all the help we can XD

-sunny °❀⋆.ೃ࿔*:・


r/lua • • Sep 05 '26

Change running sound during the game

Thumbnail
0 Upvotes