lua-debug
lua-debug copied to clipboard
View class object property values when debugging?
I'm using luabind to bind some classes in C++ to make them available in Lua:
auto defVector = luabind::class_<Vector3>("Vector");
defVector.def(luabind::tostring(luabind::self));
defVector.def(luabind::constructor<>());
defVector.def(luabind::constructor<float, float, float>());
defVector.def_readwrite("x", &Vector3::x);
defVector.def_readwrite("y", &Vector3::y);
defVector.def_readwrite("z", &Vector3::z);
// ...
When debugging a Lua script, I would like to be able to see the values of the x, y and z properties for variables of this type, but this does not seem to be possible at the moment:

Could something like this be implemented?
Alternatively, it would be useful to see the __tostring text of the value. In the ZeroBrane IDE you can hover over a variable to view its __tostring text:

It's very useful for debugging, especially when working with math-type classes.
You can add a method __debugger_tostring to the metatable.
You can add a method
__debugger_tostringto the metatable.
Works like a charm, thanks! I think it would be a good idea to put this in the readme, since it doesn't seem to be documented anywhere at the moment.
One more thing:
Would it be possible to allow us to overwrite the displayed type of the values? At the moment, it just says "userdata" for custom types:

The points table has values of types {Vector,Vector,EulerAngles}, but it just says {userdata,userdata,userdata}, which is not very helpful. Maybe another metatable function, like __debugger_gettypename?
You can set __name in metatable.
It really should be documented, but the problem right now is that there isn't any documentation.
You can set
__namein metatable.
I did try setting __name, but it didn't seem to have any effect:

__name is set in the metatable, but it still shows as userdata. Here's how I'm pushing the __name string into the table:
lua_pushstring(l, "__name");
lua_pushstring(l, "Test");
lua_settable(l, -3);
I also tried pushing a getter function instead (i.e. the same as __debugger_tostring), but that did not work either.
Well, it didn't work as expected. I'll fix it in the next version.
I tried commit b179c3c, but it doesn't seem to be working yet:

It still says userData for the types, and there is now an additional nil entry at the start.
If the feature is still work-in-progress, just ignore me 😅.