I am actually trying to create a class in C++ to encapsulate calls of Lua, actually trying to encapsulate a function to load a Lua script on the constructor, but the main problem is when I try to make a function call of the Lua script I can’t find how to store the multiple returns value and how to correctly push all the arguments.
I’m trying to find an idea of the implementaion of a function who call a lua fonction with any number of any type of parameter, (the function will push arguments and call the function, but i dont want dynamic cast for example to know if i have to “lua_pushnumber” or push string for example.
You could try to accept an array of some type of variant class in your constructor, and use their type to determine how to pump them into Lua. On the other hand, there is really only two types that are interchangeable between C/C++ and Lua: string and number/double. A possible solution is to give pass in an array of strings (or a char** and an int, if you prefer), passing in your doubles as strings as well.
You could then do your loadstring() call by appending a string representation of your string or double after the string “return “. When you execute the function pushed to the stack by loadstring(), the lua engine will push your variable (string or double with appropriate type) to the lua stack. You would have the overhead of string-parsing your doubles, but if you were dying for speed I bet you would be coding purely in C++ anyways 🙂 The advantage of this method is that you could actually pass in a function this way too: (i.e. “return function() print(“hello”); end”)