LuaJIT and Rocks? - lua

Just a small question from a "Lua newbie"...I have been using LuaJIT and it is awesome, no the question is since LuaJIT is Lua 5.1 compatible does that mean I can use all the "LuaRocks" that standard Lua uses in LuaJIT?
For instance if I wanted to install one of the SQLite libraries (e.g. http://luaforge.net/projects/luasqlite/) - how would I install that in LuaJIT?
Do all the available "LuaRocks" work out the box with LuaJIT?

LuaJIT is designed to be drop-in compatible with the Lua stand-alone. There is no reason why any purely Lua-based Rocks shouldn't work. DLL-based Rocks ought to work as well, since the LuaJIT stand-alone DLL is compatible with the original DLL.

Concretely:
"LuaJIT is fully upwards-compatible with Lua 5.1. It supports all standard Lua library functions and the full set of Lua/C API
functions. LuaJIT is also fully ABI-compatible to Lua 5.1 at the
linker/dynamic loader level. This means you can compile a C module
against the standard Lua headers and load the same shared library from
either Lua or LuaJIT."
I think that pretty much says it all.

Related

whether Lua or LuaJIT is used in Apache APISIX

What are the benefits of using Lua or LuaJIT for APISIX? What is the relationship between Lua 5.1, Lua 5.3 and LuaJIT?
Apache APISIX claims to be based on OpenResty (Nginx + LuaJIT). This is because LuaJIT has better performance than Lua, and has a FFI library for interacting with C code.
Source: https://apisix.apache.org/blog/2021/08/25/why-apache-apisix-chose-nginx-and-lua/#luajit-vs-go
What is the relationship between Lua 5.1, Lua 5.3 and LuaJIT?
LuaJIT is based on Lua 5.1, and Lua 5.3 has very little relation to either of them.
There is a small cherry-picked handful of features backported or re-implemented from 5.2+ in LuaJIT, for example the bit library is there to replace 5.2's bit32, but LuaJIT for the most part is just a JIT implementation of 5.1, which makes Lua 5.3 the odd one out.
I think a point needed to be claimed before that the Apache APISIX do choose the Openresty which Lua wrote. So maybe this is why Your question was scored negatively.
Then let's return to the question, What is the benefit of using Lua or Luajit. You can refer to this link

Using external modules with statically linked lua

Recently, I've purchased a game that uses lua for modding support. Unfortunately, lua has been statically linked and there are no dll's at all. It appears to be running lua 5.2 and I don't think any of the lua functions have been modified. I don't have access to the source but debugging info was included with the executable. I'm attempting to use an external library (luasockets) which seems to come with it's own version of lua (lua5.1.dll). Loading the library causes the game to immediately crash without a useful stacktrace. any way to make this work short of rewriting all the lua functions in the exe?

Has anyone built Lua 5.2 for OpenWRT?

I'm curious if anyone here has built Lua 5.2 for OpenWRT?
All Google brings up is this thread disparaging Lua 5.2's new environment system, and noting how LuCI won't work with Lua 5.2.
However, I am not at all interested in using LuCI or, for that matter, most of the other Lua code supplied by OpenWRT. Compatibility with LuCI etc. is not an issue.
Therefore my question: Has anyone compiled Lua 5.2 for OpenWRT? Do all the OpenWRT patches apply cleanly? I suspect they don't; at any rate, the LNUM author has said he does not plan on supporting his patch.
Basically, I would like to know if building Lua 5.2 is feasible/has been done/sounds doable before I plunge in, lose two weeks to frustration and am then forced to give up.
I build 5.3.2 for OpenWRT Mips32r2. Should be work with 5.2.4 too.
https://github.com/markuman/zsun_fun/blob/master/mips_cross.sh

How can I detect at runtime if I am running Luajit or PUC Lua 5.1?

I am writing some test scripts for my Lua project and I want to be sure that they run correctly under the different Lua versions available. Since my unit testing framework can use the wrong Lua version if I misconfigure it, I would like to be extra safe and check at runtime what Lua version my tests are running under. What would be the best way to do that?
I know that a quick way to tell 5.1 and 5.2 apart is to check the _VERSION global but how can I tell regular Lua 5.1 and LuaJIT apart?
Luajit extends the standard library with a jit module. That is probably a more direct way to detect its presence:
if type(jit) == 'table' then
print(jit.version) --LuaJIT 2.0.2
end

Starting Lua, what to use?

I'm trying to learn Lua, but I don't really know which binary to download. There's 2 choices:
Lua Binaries
Lua for Windows
The second option Lua for Windows seems to be the recommended option, but the installer weighs in at 26.6Mb, which is pretty hefty for what is supposed to be a v.lightweight language.
I'm thinking of using Lua as a scripting language for games, and perhaps as a fast development language for file processing like how Python or Ruby does it. So it must be something lightweight, not a 26.6Mb file.
Which is the appropriate one to download and start?
Luaforwindows, no doubt. It's simpler, easier and faster.
The installer comes with lots of stuff (Scite editor & several extra libs if I remember well). But the installer asks you before installing all those extra stuff. Just install the minimum and you will be fine.
Lua for Windows includes a handful of other, useful libraries and tools. The actual Lua executable included is still tiny, in the 1-2MB range as expected.
Having the extras there already will only make things easier, and disk space is cheap: go with Lua for Windows.
You may also want to check ZeroBrane Studio, which is only 4M download on Windows and is based on the same editor as SciTE that comes with Lua for Windows. ZBS also comes with 50+ Lua examples and few simple lessons to get started quickly with Lua programming.
Quoting from here.
Installation
The LuaBinaries files are intended for advanced users and programmers who want to incorporate Lua in their applications or distributions and would like to keep compatibility with LuaBinaries, so they also will be compatible with many other modules available on the Internet.
If what you want is a full Lua installation, please check other projects such as the Lua for Windows and LuaRocks.
Seems quite clear to me that you should download Lua for Windows.

Resources