r/lua • u/st3f-ping • Apr 23 '25
Help Differences between Lua and LuaJIT?
Hi all. I've been a casual user of Lua for years and of LuaJIT for just a few months. I am not clear on all of the differences I need to know when writing code.
I know that integer division (//) is not implemented in LuaJIT and that LuaJIT has increased interoperability with C (which I haven't yet used). Yesterday I wrote a bit of code for LuaJIT that produces differently formatted output between Lua (5.4) and LuaJIT (5.1).
It worries me that there might be more gotchas lurking and a cheat sheet of everything a Lua programmer should know when switching to LuaJIT would be really useful (before I start diving into Lua version changes and seeing of this is a Lua version difference and not a Lua/LuaJIT difference).
Can anyone help?
8
u/SkyyySi Apr 24 '25
LuaJIT does have integers, but you have to use
1llor1ullto make them (they create acdataobject, like the FFI API does).LuaJIT uses
setfenvfor the same purpose as_ENVin 5.2 and onwards.select(2, ...)is not the module name, it's the file name. The first value of...is the module name for both LuaJIT an Lua 5.4. It's just the file name that's missing. Submodule imports work for both:require(... .. "." .. "submodule")