r/lua

▲ 0 r/lua

What's the smallest, most useful change you could make to Lua?

Lua's superpower is staying small. Fennel, MoonScript and YueScript are wonderful answers to "what if Lua were a different language?" — and I've learned a lot from all three. So now I'd like to ask another question. Suppose we keep Lua (mostly) as is, then **what's the minimum change to Lua that buys the most? **

My current answer is `luk`, a 120 line transpiler that plugs into `require` to load Lua code that :

- adds list and dictionary comprehensions
- a uses Python-style indentation for blocks (so no nee for `do`, `then`, `end`
- replaces `function` with `fn`,
- replaces `^` for return, `
- expands `x := y` o `local x = y`

For example:

Luk code (on left) transpiles to Lua (on right)

Explicit `then/do/else/end` still works, so any Lua is (almost) valid luk and the two styles mix freely. The whole transpiler is one ~120-line module — no parser, no AST, no dependencies. The generated Lua keeps the source's line numbers exactly (errors point at the real `.luk` line), and a `require()` hook lets `.luk` and `.lua` modules interoperate with no build step.

luarocks install luk # cli + a small stdlib battery included

**An invitation, and a constraint:**

- What did I miss? What tiny change to Lua would pull the most weight for you?

PRs welcome, under one hard rule:

- the transpiler may never exceed 250 lines. If your feature can't pay for itself inside that budget, it doesn't go in. (That rule is the my whole design philosophy.)

- quick tour: https://timm.fyi/luk.html
- longer tour: https://github.com/aiez/luk/blob/main/README.md
- code: https://github.com/aiez/
- luarocks: https://luarocks.org/modules/timm/luk

reddit.com
u/timmem — 15 hours ago
▲ 47 r/lua

Python's CSV got a Competitor!

After spending more than 2 weeks, finally i published a module for CSV in lua that lua actually needed. It's not another CSV module, it's a direct competition of python's inbuilt CSV. The name of the project is "sheets" and that's what the lua was missing for years. A fast, memory efficient, CSV library written in C with lua C API as wrapper.

Also, the library is well documented and released as a serious open source project, not a fuzzy module.

Check NNEngine/sheets on luarocks and GitHub.

u/Ok-Comparison2514 — 2 days ago
▲ 6 r/lua

Is there a way to return the act of returning to a function?

Example

local function b()
    return
        (math.random(0, 1) == 0),
        0
    ;
end

local function a()
    local return_early, value =
        b()

    if (return_early) then
        return (value);
    end

    --[[ Continue function a ]]
    return (1);
end

print(a())

but I want to do it more like, having function b directly tell function a to return early rather than function a having to check itself

I want more like this where I used "return return" as sudo code for throwing the return up 1 level

local function b()
    if (math.random(0, 1) == 0) then
        return return (0);
    end
end

local function a()
    b()

    --[[ Continue function a ]]
    return (1);
end

print(a())
reddit.com
u/128Gigabytes — 4 days ago
▲ 9 r/lua

When using "return" in a function, should I use only "return" or "return nil"?

I was writing a simple script in lua and ran into this dilemma: whether to use return with nil or without the nil. Using nil seems more correct, but it’s more verbose. What return style should I use?

local function foo()
  return
end

local function bar()
  return nil
end
reddit.com
u/drizzlemox — 3 days ago
▲ 226 r/lua+1 crossposts

LUA DS Algorithm Visualizer

The Online Lua Compiler & Algorithm Visualizer https://8gwifi.org/online-lua-compiler/

currently supporting
1D arrays (tables) — {1, 2, 3}, dense integer-keyed tables
2D arrays (nested tables) — {{1,2},{3,4}}
Maps / hash tables — tables with non-sequential or string keys
Linked lists & trees — node tables ({ val, next } / { val, left, right })
Console — print
Control flow — functions (incl. recursion)

Looking for feedback and Bug's appreciated

u/anish2good — 7 days ago
▲ 3 r/lua+1 crossposts

hyprlang to lua help

hi guys so i heard hyprland is switching to lua ... i dont have enough experience can someone pls help me out or something to change it .

reddit.com
u/Own-Election2312 — 6 days ago
▲ 31 r/lua

Why there is no port of python libraries to lua?

Lua is truly a fantastic language with many advantages.

It's easy to use and understand, and much faster than Python. I believe it could be a better alternative to Python, as both are interpreted languages.

So why not migrate Python libraries to Lua?

I understand that Lua's best use is integrating with other systems due to its small size and good compatibility with C.

I think the only real advantage Python offers is its integrated environment. If Lua had this feature, there would be no need for Python.

I know this might sound a bit optimistic, but I'd like to know if there are any other limitations preventing this?

Thank you in advance.

Edit: I want to thank everyone who commented on this post, I learned a lot from all of you and made me look at the topic from a new perspective.

reddit.com
u/IAlwayswantToLearn — 8 days ago
▲ 86 r/lua+1 crossposts

My first game made with Lua and amazing Usagi Engine 🩷

I just released my first game made with Lua and amazing Usagi Engine 🩷 Well known mechnics with modern twists. Place blocks, clear lines, choose upgrades and repeat. That's all! Simple, but addictive.

At first, I just wanted to test Usagi Engine in action. Since the development turned out better than planned, I decided to publish the result of my work on itch.io. You can check out Lua and Usagi in working game example.

Play in browser or download (win, mac, linux)
https://luko81.itch.io/the-game-about-blocks

u/1killaHertz — 8 days ago
▲ 0 r/lua

looking for collaborators on my shooting game

well as the title says i need active collab cuz there is NO way im coding this all by myself as a 12 yr old

reddit.com
u/Pristine-Anything487 — 6 days ago
▲ 0 r/lua

OmniLua - Rust implementation of Lua 5.1 - 5.5 targeting web use and sandboxing

[Github here] (https://github.com/ianm199/omnilua/tree/main)

Website + docs

I've been working on OmniLua for a bit now - it builds one binary that can run Lua 5.1 - 5.5 from one binary.

The main motivation for this was there seemed to be a gap for game development in the Rust community where mlua cannot be run in the browser, so games built in engines like bevy can't compile to wasm32-unknown-unknown.

There is some other benefits - like being able to easily use Lua in Cloudflare workers or in "playground" developer tools.

Highlights:

  • Targets 100% conformance to reference Lua for all 5 versions
  • Can run LuaRocks and install Lua only packages
  • Performance is slower than C Lua 5.4.7 but within ~40% on standard benchmarks. Performance chart here
  • API is 100% compatibile with mlua

Try it:

cargo install omnilua-cli

export OMNILUA_VERSION=5.5

omnilua -e 'print("hello")'

omnilua # opens repl

I used AI heavily to develop this I wouldn't consider it "vibecoded" however.

u/ianm818 — 7 days ago
▲ 83 r/lua+2 crossposts

My first Love2d Project : Raycaster

Hello everyone this is my first post for my very first project in love 2d with I am brand new to Game Development and any kind of programming. I'm learning Lua Programming as well as Love2d I have been learning it for about 2 days and this is all I have to show for it. I am making this free MIT License open source on GitHub for people who want to try out love2d its easy to Modify and turn into exactly what you need it to be this is just giving people a jump start how to I share a Link to my GitHub without getting Banned lol?

u/Separate_Escape_7748 — 10 days ago
▲ 4 r/lua+2 crossposts

Luau ported from C++ to pure Rust (passes all tests)

luaur is a pure-Rust port of Luau (Roblox's typed Lua) - lexer, parser, bytecode compiler, register VM, type checker, and the CLIs. It builds for wasm32-unknown-unknown with no C toolchain, so you can run and type-check Luau right in the browser: https://pjankiewicz.github.io/luaur/

About 2 weeks ago on a whim I decided to do this. Why? I wanted to use Luau but in a way that's first-class in the Rust ecosystem and targets wasm32-unknown-unknown. Lua is a great embeddable language and it serves me well as a scripting language for AI agents - and being able to type-check a script before I execute it is another reason it's a good fit.

That's the why. Here comes how.

Since the LLM boom started I fantasised about porting large projects to Rust with a systematic approach. The cleanest one is graph-based: build a graph of the source project, sort it topologically to fix the translation order, and keep expanding the context with the items you've already translated. Then you can translate the whole thing in one clean sequence. That's a well-known "skeleton" strategy - that was assumption one.

Assumption two: do the porting with small, cheap models guided by the graph harness. With the right context I believed even small models produce passable output - we've leaned so hard into multi-turn frontier agents that it's easy to forget how much a small model can do when the context is right.

With both assumptions in place, building the tool and filling the skeleton took about 2 weeks of not-very-intense work - mostly monitoring and nudging Claude and Codex (I used them interchangeably) to stay on target. Sometimes the agents forgot they were supposed to do batch parallel translation with the cheap models. Claude or Codex would say "the cheap models are clearly too weak, let me translate this myself." My nudge was always the same: use the translation tool, fix the systematic context errors. In 9 out of 10 cases the problem was the context - the hallucinations and bugs were missing-context errors, not model quality.

After a few days a stable loop emerged:

  • pick a module
  • translate it in a batch
  • fix it in a batch (rotate the models)
  • let the agent fix the rest until the project is green
  • repeat

The last stretch was purely agentic: setting up the crates, fixing tests, getting it working across platforms.

Now - does auto-translated code actually work? That's the part I cared about proving, so the oracle is Luau's own tests, not mine:

  • 5,347 of Luau's own unit tests, ported to Rust, pass.
  • 293/293 upstream conformance scripts run byte-identically on the Rust VM.
  • a byte-exact bytecode differential: bytecode compiled by C++ Luau runs on the Rust VM with identical results.
  • the safe API layer (luaur-rt, mlua-style) passes 225/235 of mlua's own test suite byte-for-byte; the other 10 are documented Lua-vs-Luau differences.

Repo: https://github.com/pjankiewicz/luaur

reddit.com
u/mosquit0 — 11 days ago
▲ 30 r/lua+1 crossposts

Cat2D – A Mobile-First Lua Game Engine for Android Focused on Performance

🚀 Getting Started with Cat2D – Loading and Centering an Image

Hi everyone!

I'm the creator of Cat2D, a new Lua game engine for Android focused on performance, simplicity, and community-driven development.

Today I wanted to share a simple example that loads an image and automatically centers it on the screen.

local player

local scale = 0.5

function load()

player = graphics.loadTexture("player.png")

end

function draw()

graphics.clear(0, 0, 0, 1)

if player then

local sw = system.getScreenWidth()

local sh = system.getScreenHeight()

local w = player:getWidth() * scale

local h = player:getHeight() * scale

local x = (sw - w) / 2

local y = (sh - h) / 2

graphics.draw(player, x, y, 0, scale, scale)

end

end

What this example demonstrates

Loading a texture with graphics.loadTexture()

Getting the screen resolution with system.getScreenWidth() and system.getScreenHeight()

Reading texture dimensions with getWidth() and getHeight()

Scaling an image to 50% of its original size

Automatically centering the image on any screen size

Cat2D's goal is to make creating games and applications in Lua on Android simple while still exposing powerful native features and maintaining good performance.

The engine is still evolving and I'd love feedback from other developers.

What features would you like to see in a mobile-first Lua game engine? 🐱🚀

u/Cat2DEngine — 11 days ago
▲ 8 r/lua+6 crossposts

Leadwerks Summer Games tournament begins

Hi guys, in this week's live developer chat we are kicking off the Leadwerks Summer Games Tournament. Participants have 30 days to create a simple playable game (with Lua or C++) and upload it to our website. Instead of a competition, this is a co-opetition. Everyone who participates gets a prize in the mail. 😃

We also played through the free game Exit: Underground and took a sneak peak at some of the plans for development in Leadwerks 5.2, including fast software raytracing and moving our VR backend to OpenXR.

If you are interested in participating in the tournament, you can pick up the Lua-enabled Leadwerks Game Engine 5 with a discount during the Steam summer sale.

youtube.com
u/MichaelKlint — 8 days ago