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

operator int() exits break mode in devcat debugger #1484

Closed UltraEngine closed 1 year ago

UltraEngine commented 1 year ago

If you bind any class with an operator int() method, it will cause an error with the devcat Lua debugger.

struct TESTCLASS
{
    operator int() const
    {
        return 0;
    }
};

L->new_usertype<TESTCLASS>("TESTCLASS");

When you debug any Lua program, variables appear correctly in the sidepanel display, but hovering the mouse over a variable will cause the program to exit break mode and continue executing: Any simple program will do it:

local a = 0-- <-- 2. Hover the mouse over the letter 'a' and the program will jump to step 3

local b = 0-- <-- 1. Set a breakpoint here

local c = 0-- <-- 3. Set breakpoint here

The reason I am using this operator is so I can do things like this in my C++ table class:

table t;
t["health"] = 100;
int h = t["health"];

This is probably the same problem I had when I tried to integrate nlohmann::json with sol.

UltraEngine commented 1 year ago

Here is one possible solution, but it's ugly:

struct TESTCLASS
{
    operator int() const
    {
        return 0;
    }
};

struct TESTCLASSWRAPPER : private TESTCLASS
{};

L->new_usertype<TESTCLASSWRAPPER>("TESTCLASS");
UltraEngine commented 1 year ago

I was able to implement a fix for this using the wrapper technique described above. The debugger works correctly now with C++ tables.