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.06k stars 493 forks source link

Critical: luajit can't pass nil as sol::object argument #1474

Closed deadlocklogic closed 12 months ago

deadlocklogic commented 1 year ago
  1. Repro
    
    sol::state lua;

lua["test1"] = { std::cout << "ok1" << std::endl; }; lua["test2"] = [](sol::object, sol::object) { std::cout << "ok2" << std::endl; }; lua.script("test1(nil)", [](lua_State, sol::protected_function_result pfr) { sol::error err = pfr; std::cout << err.what() << std::endl; return pfr; }); lua.script("test2(nil, nil)", [](lua_State, sol::protected_function_result pfr) { sol::error err = pfr; std::cout << err.what() << std::endl; return pfr; });


2. Both scripts gives the following error:

stack index 1, expected anything, received nil: stack traceback: [C]: in function 'test1' [string "test1(nil)"]:1: in main chunk stack index 1, expected anything, received nil: stack traceback: [C]: in function 'test2' [string "test2(nil, nil)"]:1: in main chunk



3. Compiler/IDE: Visual Studio
    Language: C++
    sol2 version: latest

I am facing a bug related to this one.
@ThePhD Am I missing something here? Because this fundamental kind of bugs are scary.

Thanks.
ThePhD commented 12 months ago

This is fixed in the latest commit, https://github.com/ThePhD/sol2/commit/ff3f254f7b47cfc8cf2976368d86f4cd726915ec

deadlocklogic commented 12 months ago

@ThePhD Hi, I pulled the repo to the latest, still getting the same issue: stack index 1, expected anything, received nil.

Thanks, I appreciate your efforts for bringing this nice library.

roman-orekhov commented 12 months ago

@deadlocklogic did you try this fix?

deadlocklogic commented 12 months ago

Apparently I was linking against the vcpkg library instead of the main repo. Indeed the issue is fixed. Apologies.

@deadlocklogic did you try https://github.com/ThePhD/sol2/issues/1344#issuecomment-1624548126 fix?

This fix is peculiar since it silences critical sections.