ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.18k stars 515 forks source link

Requiring compat53 with LuaJIT fails #1542

Open cassava opened 11 months ago

cassava commented 11 months ago

Versions:

Problem: When requiring "compat53" module when LuaJIT is used, I get a curious error.

Output:

$ ./build/Debug/sol_compat53
[sol2] An error occurred and has been passed to an error handler: sol: runtime error: /usr/local/share/lua/5.1/compat53/init.lua:1: attempt to index global '_VERSION' (a string value)
stack traceback:
    /usr/local/share/lua/5.1/compat53/init.lua:1: in main chunk
    [C]: in function 'require'
    [string "..."]:2: in main chunk
terminate called after throwing an instance of 'sol::error'
  what():  sol: runtime error: /usr/local/share/lua/5.1/compat53/init.lua:1: attempt to index global '_VERSION' (a string value)
stack traceback:
    /usr/local/share/lua/5.1/compat53/init.lua:1: in main chunk
    [C]: in function 'require'
    [string "..."]:2: in main chunk
[1]    255547 abort (core dumped)  ./build/Debug/sol_compat53

Source: sol_compat53.cpp:

#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>

int main() {
    sol::state lua;
    lua.open_libraries(sol::lib::base, sol::lib::package);

    lua.script(R"(
        require("compat53")
    )");
}

Here is the line that fails...

$ cat /usr/local/share/lua/5.1/compat53/init.lua | head -1
local lua_version = _VERSION:sub(-3)

Compile-Command:

/usr/bin/c++ \
  -DSOL_LUAJIT \
  -isystem [sol2-3.3.1]/include \
  -isystem [luajit-2.1.0-beta3]/include/luajit-2.1 \
  -m64 -g -std=gnu++17 \
  -o sol_compat53.cpp.o \
  -c sol_compat53.cpp

If I add a print statement above the require:

print(_VERSION)

I get the expected "Lua 5.1".

I feel like I'm missing something substantial, but I'm at a loss.