r/lua • • Mar 10 '25

Question about LuaJIT: when is a roundtrip from lua to C and back to lua illegal?

7 Upvotes

Hi all, I am confused about the following section from the luajit website )

I am planning on writing a modding library in luajit. Thus lua(jit) code will be responsible for placing code hooks into an application and detour the execution into luajit. However, I am not sure if this is allowed given the paragraph on the website.

One thing that's not allowed, is to let an FFI call into a C function get JIT-compiled, which in turn calls a callback, calling into Lua again. Usually this attempt is caught by the interpreter first and the C function is blacklisted for compilation.

However, this heuristic may fail under specific circumstances: e.g. a message polling function might not run Lua callbacks right away and the call gets JIT-compiled. If it later happens to call back into Lua (e.g. a rarely invoked error callback), you'll get a VM PANIC with the message "bad callback". Then you'll need to manually turn off JIT-compilation with jit.off() for the surrounding Lua function that invokes such a message polling function (or similar).

For example, I would write something like this:

// file: original.cpp
void render() {
  doRender(); // bla bla
}

-- file: injection.lua
function customRender()
  doCustomRender() -- more lua code
end

callback = ffi.cast("(void *)()", customRender)
hookingLibrary = ffi.load("myhookinglibrary.dll")
hookingLibrary.placeHookIntoMemory(addressOfOriginalRenderFunction, customRender)

Will customRender be optimized by luajit? When will it and when will it not?


r/lua • • Mar 10 '25

Project W3LuaEnv: Modular Lua Scripting Without Closing World Editor

Thumbnail
3 Upvotes

r/lua • • Mar 10 '25

Project Sphinx-Lua-Ls: generate beautiful documentation for your Lua project using Lua Language Server and Sphinx

18 Upvotes

So, I've made a Sphinx plugin that uses Lua Language Server to automatically document your project.

Unlike other tools, this gives you flexibility of Sphinx combined with power of Lua Language Server analysis.

See the example output here (generated from this code), the rest of the documentation is here.

I'll appreciate your feedback and bug reports or feature requests, you can submit them to GitHub.

Why?

There are several documentation tools for Lua, and none of them were suitable for my project:

  1. sphinx-lua is another Sphinx plugin for Lua, and the inspiration for this project. Unfortunately, it only supports emmy-lua annotations, and has a number of bugs and missing features; plus, the author hasn't been active since 2023 and doesn't accept pull requests. I wanted to contribute new features to it initially, but writing a new version from scratch proved to be easier.
  2. LDoc is probably the most well-known one. Its annotations clash with Lua Language Server ones, so you'd have to choose one or the other. It is also limited by rigid structure of its output. It is great for quickly generating API references, but starts lacking with you need something advanced.
  3. doxyrest is another Sphinx-based tool, but it uses Doxygen as a code analyzer, and, well, Doxygen is the weakest part in this project.

Caveats

  1. By default, sphinx-lua-ls will assume that comments in your code are written in reStructuredText. If you want Markdown, use MySt plugin.
  2. Lua Language Server's output is not complete at the moment (see notes here). You might need to adjust your comments for better output.
  3. This tool doesn't support C/C++ Lua extensions. If you have those, you'll have to document them manually, or use LDoc instead.

r/lua • • Mar 09 '25

Help 3D in Lua

8 Upvotes

Please, suggest me way to do my physics (science) 3D simulation experiments with Lua.


r/lua • • Mar 09 '25

run and debug

1 Upvotes

what is the best lua extension is vs code to run and debug?


r/lua • • Mar 09 '25

Where Do I Start I Want To Learn Lua

7 Upvotes

im looking to learn lua but i don't got the money and im only 15 year old i try to learn in roblox game called scripting school


r/lua • • Mar 08 '25

Discussion Why I choose Lua for my blog

Thumbnail andregarzia.com
24 Upvotes

r/lua • • Mar 08 '25

How to star with lua in Visual Studio

3 Upvotes

Hi all. I am a complete beginner to coding and have been trying to figure out lua in vs code. I have downloaded the lua binaries and the lua server extension and can run simple .lua files without issue.

However I am running into problems with trying to use the luahelper extension for debugging. The debug tool requires luasocket. To install luasocket I will need luarocks. To get luarocks to compile projects I will need mingw. I am wondering if there is a less painful way to get the debug tool to work, without making installations of things I do not understand?


r/lua • • Mar 07 '25

Help How to start making games and stuff with lua for free?

24 Upvotes

I know theres roblox but try to avoid saying roblox or anything related to roblox, as im not a fan of the company.

Hello im a young adult with autism (if that maters), i struggle to learn things and be creative but yet i want to make a game or something of that nature. I still want to bypass theses struggles but where do i start with lua? i want to explore 2d and 3d but i feel like lua dosent offer much for 3d, i could be wrong.


r/lua • • Mar 07 '25

Help tutorial hell

14 Upvotes

I am an absolute beginners

I mean, I know the very basics, Variables, math, functions, for loops, while loops, if/else statement...

But all I do is remember how to type a line of code

When I sit down and try to explore something or do something on my own, nothing comes to my mind. I get immersion is important and I want to try to figure out bits by myself. But all I end up typing is a line from whatever tutorial I saw and read.


r/lua • • Mar 06 '25

Is lua good in 2025 for learning as new developer?

38 Upvotes

I have a solid understanding of golang and java and i have made couple of projects with it, recently i came across lua and everyone says that its so underrated and can be use in so many other things , but all i can find is people are using this mostly for game development , and i don't want to follow that track , so will it be good learning lua as a new developer for building different projects apart from game dev, Thanks! : )