luawrapper
luawrapper copied to clipboard
Member function not being added in Lua-space
So I have an object of type CallbackTimer. There is a method CallbackTimer::start, which takes no arguments and returns nothing. If I add it into Lua like this:
lua.registerFunction("start", &CallbackTimer::start);
...then for some reason it won't show up in Lua. Printing out the value of CallbackTimer.new().start shows that it's nil. I have also been having other problems binding functions that return void or accept no parameters to Lua-space (I get a compiler error, forgot which one).
Is this a new bug?
I've added a test case just in case (https://github.com/Tomaka17/luawrapper/commit/224168bae24277b83f7f4c3a2a9809236219206e) but it works. I have also tested this on the previous version and it works too.
The problem may come from your new() function.
Also you should call start with :start and not .start.
It is entirely possible that that is the case. When you're running on three hours of sleep and pizza, that tends to happen. I'll get back to you on that.
The issue is not the distinction between object:method and object.method; I can't call theCallbackTimerObject:start() because theCallbackTimerObject.start (note the lack of parens) is nil, and thus doesn't even exist. Thor.CallbackTimer.new() is just implemented as []() { return CallbackTimer(); }.
I think this is being caused by #20. thor::CallbackTimer inherited the method start() from the thor::Timer class. This is a pretty big issue that makes binding libraries harder. I haven't tested it yet, but I think it's possible to bind a custom member function that calls the method.
Edit: I think this issue can be closed, there is a solution in #20.