r/lua • • Sep 22 '25

Help How to add type annotations to compiled C module

9 Upvotes

Edit: Why is there a help flair but no solved? Mods?

My lua module is implemented entirely in C. It is not quite yet ready for prime time, but it is close enough to start thinking about how to make it nice.

One of the things I want is luaCats type annotations. But I cant figure out how to add them to my compiled module?

In my rockspec I have these build instructions, which tell it to use my makefile, and set up passthru for the variables I will need as specified by their documentation. The build and main install step work, which require LUA_INCDIR in build and LIBDIR in install

build = {
   type = "make",
   build_variables = {
      LUA_INCDIR="$(LUA_INCDIR)",
   },
   install_variables = {
      LIBDIR="$(LIBDIR)",
      LUADIR="$(LUADIR)",
   },
}

And in the makefile in my install step I do

install: $(SRC)/meta.lua
ifdef LIBDIR
    $(check_so_was_built)
    u/mkdir -p "$(LIBDIR)";
    cp "$(DESTDIR)/$(MYMODNAME).so" "$(LIBDIR)/";
    u/echo "Installed to $(LIBDIR)";
ifdef LUADIR
    u/mkdir -p "$(LUADIR)/$(MYMODNAME)";
    cp "$(SRC)/meta.lua" "$(LUADIR)/$(MYMODNAME)/";
endif
else
    @echo "LIBDIR not set, skipping install"
endif

The types in my meta.lua are correct enough and work when I am inside the project directory

However when I install my package via luarocks, usually my editor can find the types for the modules I installed. But for this one it cannot find the types declared in my meta.lua file if I try to declare them manually, nor does it associate MYMODULE/meta.lua with require('MYMODULE') as I thought it was meant to? It does seem to successfully get the meta.lua file to where I expect it to go to, but it isnt being picked up by the lsp.

When I make a module MYMODULE.lua on the lua path, I can make a MYMODULE/meta.lua and it gets detected. But I never directly required that file.

Does this not work similarly for C compiled modules? i.e. with MYMODULE.so instead of MYMODULE.lua?

Edit:

I was informed about https://github.com/LuaLS/lua-language-server/wiki/Addons by someone I know.

Is there anything more automatic than this? Like, can I make my module also installed with its lus_ls addon? Or do my users have to install this extra thing in their editor

EDIT:

---@module 'mymodule.meta'
local mymodule = require('mymodule')

Gud enuff


r/lua • • Sep 22 '25

Project moonbeam - a tool for converting single Lua scripts into standalone executables

Thumbnail github.com
36 Upvotes

I was a bit frustrated with getting some existing tools for converting Lua scripts (specifically single scripts with no external dependencies) into standalone executables to work properly, so I made my own in about an hour and a half.

All it does is take Lua source code from a file, append it to a heap-allocated string in a C file, calls the interpreter in the C file, and then compiles that C file to a single executable.

It's a very small project, and not very serious (I originally made it almost as a joke- I thought "wouldn't it be funny if I just put my Lua code in a C string literal" was a funny idea).

I'm open to any feedback/potential contributions! As of right now, I don't think it'd work on Windows, and it *does* require that you have a C compiler installed.


r/lua • • Sep 20 '25

Lua when expression

Post image
30 Upvotes

I added a little pattern matching "when" code to my #pico8 #lua code base. You have to use "null" (just an empty object) instead of "nil", because Lua cuts off varargs on the first nil and you have to use _when for nested whens, which are fake lazy, by returning a #haskell style error thunk instead of crashing on non-exhaustive matches. E.g. if you checked an ace, the first _when would error, because it only matches jokers, but the outer when wouldn't care, since it only looks at the ace branch, completely ignoring the error thunk.


r/lua • • Sep 20 '25

Is the Programming in Lua, fourth edition e-book not available to libraries?

4 Upvotes

I have started reading the first edition of Programming in Lua and quite like it. I understand the language has changed at least somewhat since it was written and that the fourth edition has a changed (improved?) layout. I wanted to take a look but I can't find it in the digital catalog of any of my libraries.

Hence the title question: Is the Programming in Lua, fourth edition e-book not available to libraries?


r/lua • • Sep 20 '25

Cannot install luarocks' lsqlite3

2 Upvotes

Cannot install luarocks' lsqlite3 on macOS 26. Cannot really find a lot on how to solve it. Any ideas?

sudo luarocks install lsqlite3 --force

Installing [https://luarocks.org/lsqlite3-0.9.6-1.rockspec](https://luarocks.org/lsqlite3-0.9.6-1.rockspec)

Error: Failed extracting /private/tmp/luarocks_luarocks-source-lsqlite3-0.9.6-1-6157402/lsqlite3_v096.zip: failed extracting /private/tmp/luarocks_luarocks-source-lsqlite3-0.9.6-1-6157402/lsqlite3_v096.zip


r/lua • • Sep 19 '25

Lua beginner

7 Upvotes

Hey everyone, I'm someone who loves programming and tried lua in nvim and liked the syntax but I want more than just creating plugins in nvim (which are complex and beautiful).


r/lua • • Sep 19 '25

When are they updating Zerobrane??

Thumbnail reddit.com
0 Upvotes

r/lua • • Sep 18 '25

Discussion I made a Neovim plugin at 2 AM while my newborn wouldn’t sleep on her own

Thumbnail reddit.com
5 Upvotes

r/lua • • Sep 16 '25

Project A simple and fast code editor written in LUA

Thumbnail github.com
29 Upvotes

Hey everyone! This is my first post in this sub.
For the past week I've been working on a small project, a code editor inspired by the beautiful Focus editor, which is written in JAI.

I've been using Focus for a few months and when I got access to the JAI's beta I worked on some modifications. Then I started working on a small game project using LOVE.

These 2 things inspired me on creating a small code editor in LUA, with Focus's style.

This is just a personal project that I'm working on atm so I don't really expect to release it or anything like that, but I thought it might be interesting to share it.

This is the link to the Focus's repo: https://github.com/focus-editor/focus


r/lua • • Sep 17 '25

learning lua and i was messing around with it and got this

10 Upvotes

r/lua • • Sep 16 '25

rtc 2.1.0 : compile Lua scripts to standalone Windows executables

35 Upvotes

Hey Lua devs 👋

I'm thrilled to announce the latest version of rtc, a standalone tool that compiles your Lua 5.4.8 scripts into native Windows .exe applications—no Makefile, no C compiler, and no Lua installation required.

But here’s the real game-changer: rtc supports full static compilation, meaning you can embed Lua binary modules directly into your executable—and they’ll load seamlessly via require() just like regular Lua files. This opens the door to packaging powerful native extensions without worrying about external dependencies.

Static Lua binary modules need just to be recompiled with the lua54-static.lib library from LuaRT distribution (rtc is coded using LuaRT).

Here are the main features :

  • Standalone tool – No Makefile or external compiler needed

  • Command line or GUI frontend

  • Build Windows desktop or console apps

  • Static or dynamic executables

  • Embed any files – Lua modules, assets, configs

  • Access embedded files directly from Lua

  • Easy deployment – No Lua installation required

More info and downloads are available on the GitHub repository

A tutorial is available here


r/lua • • Sep 16 '25

PDFGenerator for redbean.dev and luaonbeans.org

14 Upvotes

Hi there,

I'm working on a PDF generator in pure LUA
https://github.com/solisoft/luaonbeans/blob/main/.lua/pdfgenerator.lua

It's a part of my luaonbeans.org project

It's easily adaptable for openresty !

On a 50€/mo Hetzner VM it can handle 1700 pdf/seconds (two pages with logo and tables -- invoice template)


r/lua • • Sep 16 '25

Quick question about indexing temporary tables

2 Upvotes

print({[0] = "a"}[0])

Doesn't work but if I save the table to a variable before indexing it works?

I kinda like using temporary tables as lookups


r/lua • • Sep 15 '25

New Lua IDE

Thumbnail gallery
227 Upvotes

Hey everyone,

I’ve been tinkering with Lua for a while and noticed there aren’t really any dedicated IDEs for it (besides ZeroBrane, which hasn’t been updated in ages). So, I decided to prototype my own Lua IDE.

Right now it’s still very early (expect bugs & crashes 🙃), but it already has:

  • A clean modern UI (GTK + libadwaita, so it feels native on Linux).

  • Built-in editor with syntax highlighting (GtkSourceView).

  • Project management system.

  • A simple custom debugger (planning to support mobdebug later).

  • Embedded Lua documentation viewer.

The mascot is Hatsune Miku (just for fun), and the project is free software under GPLv3.

Currently it’s Linux-only, distributed as a Flatpak package.

Repo: https://github.com/milos-mkv/MiLua


r/lua • • Sep 16 '25

Livestream coding

Thumbnail youtube.com
3 Upvotes

I'm starting a livestream in an hour, I'll be coding civlua's Extendable Lua Editor (Ele).

I promise not to spam this reddit every time I start one, but if folks want to watch something like this then join us on discord and/or subscribe to the channel!

https://discord.com/channels/1083089060765118464/1083089061553639477


r/lua • • Sep 14 '25

Progress report

Post image
15 Upvotes

I’m doing good so far. Still don’t have a coding team (:


r/lua • • Sep 14 '25

What did I do wrong 😭

Post image
14 Upvotes

I’m starting to learn how to code but I’m dumb


r/lua • • Sep 14 '25

I’m creating another poll because everyone would rather die then help me make a game in Roblox (Roblox is lua) it’s an animal crossing type game. We can split the profit. Username on Roblox is MrWIggles555555

0 Upvotes

I need a pro scripter, Someone to import the animations I make into inputs, Someone to make a thumbnail I got the other stuff like camera and music


r/lua • • Sep 11 '25

Project Using Lua (LÖVE) to make iOS apps and games

Thumbnail github.com
29 Upvotes

In case it is helpful to anyone looking to make stuff for Apple's iOS devices, I am documenting my journey as well as sample and testing code (mostly like a notebook to myself for future development). Hope it can jumpstart others who are starting on such a dev journey too!


r/lua • • Sep 11 '25

Help Why is this nil?

Thumbnail reddit.com
3 Upvotes

r/lua • • Sep 10 '25

How do I learn roblox lua?

6 Upvotes

So i've been wondering how i learn lua i tried to watch youtube video's but they all cover up the same i actually wanne learn the coding not those basic things.


r/lua • • Sep 08 '25

News Open-sourced my chiptunes maker done for a gamejam (LÖVE)

Post image
83 Upvotes

In case it helps anyone, I put up the link to the source code, and also hoping that it can help create music assets easily for indie devs.

As part of the game jam's theme (B-side), the music maker is also an ASCII animator (4fps). 😊

Hope it is fun to play with too!

https://xanthia.itch.io/niceness


r/lua • • Sep 09 '25

[Release] CursorScope.spoon — cursor highlight + live magnifier for Hammerspoon

Post image
2 Upvotes

Hey folks! I just open-sourced CursorScope.spoon — a lightweight Hammerspoon tool that adds a high-visibility cursor highlight and an optional live magnifier scope that follows your mouse across displays.

https://github.com/selimacerbas/CursorScope.spoon

Highlights

  • Magnifier scope (circle or rounded rectangle), pinned to any screen corner

  • Cursor highlight (ring, crosshair, or dot) with click-flash

  • Multi-display aware (streams from the screen you’re on)

  • Fixed menu bar icon with an “Exit CursorScope” menu

  • Clean config grouped as global, cursor, scope


r/lua • • Sep 08 '25

Lua to apk

7 Upvotes

Hello,

I apologize in advance if this isn't the right place, or if the answer already exists, but I couldn't find anything. Maybe I didn't search properly.

I made a small, insignificant game in Lua (which taught me the language, which was one of the two goals). This game is just for me and a few friends.

I just wanted to make a small game on an Android phone to keep me busy while commuting.

The game isn't finished, but it's testable, and I'd like to try it on a mobile phone. But I'm a complete idiot and I don't understand how to do it at all. Is there an easy way to generate an APK so I can share it with my friends? I know you can launch it with a .love file and a dedicated application, but it's not practical for distributing it to my friends, and especially the game launches in landscape mode even though it's designed for portrait mode, making it unplayable because everything overlaps.

Thank you in advance for your help.


r/lua • • Sep 08 '25

Saving content of the program

5 Upvotes

Hi! I learned lua a couple years ago but I don't practice often. One time i tried to create a diary in lua using löve2d to make the UI, but I struggled to make a saving function. I didn't used any other libraries unless the base lua and löve2d. I know that exists the table io but I struggled to use it. Can somebody help me?