sol2 icon indicating copy to clipboard operation
sol2 copied to clipboard

`sol::property` and `sol::readonly_property` providing function instead of getter?

Open gradylink opened this issue 2 months ago • 2 comments

so I have this code:

extension.luaState["input"].get<sol::table>().set("mouseX", sol::property([]() { return Input::mousePointer.x; }));

when I try to log input.mouseX on the Lua side, I get:

function: 0x7bfc5bc65fe0

but if I log input.mouseX() then I get the correct integer output (Input::mousePointer.x is an int.) I don't think I'm doing anything wrong here, if I am, please point it out. I'd also like to note that I'm using Lua 5.1.

gradylink avatar Oct 18 '25 19:10 gradylink

Maybe bind your "input" as a usertype instead of a table? Then you can use sol::property to bind a getter and a setter function, which will allow you to access it as a property instead of a function call. Example here.

C3pa avatar Nov 16 '25 10:11 C3pa

Still getting the issue with this syntax:

        extension.luaState["input"]["mouseX"] = sol::readonly_property([]() { return Input::mousePointer.x; });

gradylink avatar Nov 29 '25 22:11 gradylink