I have C++ overloaded functions and want to use it in Lua. I am trying to make a generic C function (called by Lua) to call them depending of arguments. I have little experience in modern C++ and have no ideia if this is really possible.
This is a pseudocode:
void foo(int value){
...
}
void foo(std::string value){
...
}
template<Ret, Func1, Func2, ...>
Ret overload(lua_State *L){
if (lua_tointeger(L, 1))
Func1(lua_tointeger(L, 1));
if (lua_tostring(L, 1))
Func2(lua_tostring(L, 1));
}
Using LuaBridge to bind:
luabridge::getGlobalNamespace (L)
.beginNamespace ("test")
.addFunction ("foo", overload<(void (*)(int))&foo, (void (*)(std::string))&foo>)
.endNamespace ();
Is this possible? Can anyone help me?