Open JMLX42 opened 10 years ago
The fancy tuple unwrapping code may not like only doing partial unwrapping. And we'd open a larger hole where it'd happily pass too few arguments to functions.
It's possible we can add a parameter to the method() function to pass the minimum number (X) of parameters, and LuaGlue can allow sending X or more parameters. It would complicate things a bit.
The other alternative is to just ignore the fact that those methods have optional parameters in lua.
The other alternative is to just ignore the fact that those methods have optional parameters in lua.
I don't think that works. If you call a C++ method from Lua without the exact count of arguments (even counting the ones with default values) there is a segfault.
That's what I meant. Always pass the parameters.. It's annoying, but it might be the only solution.
I don't know of a good way to handle optional parameters. Even my idea of providing a min number of manditory parameters may not work due to C++ calling conventions and stuff.
OK my bad.
Today the way I do it is to use overloading or decorator functions instead of default values.
I will at some point attempt to get it to work. I'm keeping it on my todo for now.
Hello,
please correct me if I'm wrong but currently C++ methods that support default values for one (or more) arguments do not work as expected if the Lua call does not provide a value for all arguments. I think the main reason is Lua is going to try to set all of the arguments anyway, thus corrupting the Lua stack.
I've encountered the problem multiple times, and defining the LUA_USE_APICHECK reveals the problem I think.
Is it the expected behavior for now? Can we fix this using lua_gettop() and pass only what's on the stack?
Thanks,