I'm building a simple 2D game engine, and its getting bigger and bigger, exposing all of the function in Lua will be impossible: so I'm trying to automate a little bit the process, Is there anyway to get all the n arguments (with different types) from the stack at once and inject them directly into the C++ function. I already automated functions args checking. still the function binding which is a little bit tricky
For E.g: I have normal code for changing sprite position:
int LuaSprite::SetSpritePosition(lua_State* L)
{
Drawable* sprt = (Drawable*)lua_touserdata(L, 1);
int x = (int)lua_tonumber(L, 2);
int y = (int)lua_tonumber(L, 3);
sprt->setPosition(Vec2i(x, y));
return 0;
}
The concept that i want achieve is more less like this:
int LuaSprite::SetSpritePosition(lua_State* L)
{
LOAD_ARGS(Sprite*, int, int)
GET_ARG(1)->setPosition(Vec2i(GET_ARGS_FROM(1)));
LOAD_RETURN(true, x, y, 3);
return 3;
}
So
- LOAD_ARGS will get from the stack The given type respectively.
- GET_ARG(i) will get arg at index i.
- GET_ARGS_FROM(i) will do something like this x,y,z,type
I'm not requesting same behavior as it could be impossible to do, but something similar at least
And I'm sure that this isn't achievable only using 'plain' C++ and that I need also some 'magic' macros.
I'm not using the ready auto Lua binding "libraries" because there is custom structs and some functions are using complex structures and classes
I have done a lot of searching and I feel really lost.