OK, here goes the solutionThis actually proved to be simpler than expected.
I've got a class with a constructor like this:
SpecterApp::SpecterApp(std::string title, int width, int height, bool vsync, int frames)
Registering this is simple, at least with Lua 5.1. Every function to be registered needs a Lua equivalent in C++.
Like so, for the constructor.
int l_SpecterApp_constructor(lua_State * l)
{
const char * name = luaL_checkstring(l, 1);
int width = luaL_checkint(l, 2);
int height = luaL_checkint(l,3);
bool vsync = lua_toboolean(l,4);
int frames = luaL_checkint(l,5);
SpecterApp** udata = (SpecterApp **)lua_newuserdata(l, sizeof(SpecterApp *));
*udata = new SpecterApp(name,width,height,vsync, frames);
luaL_getmetatable(l, "luaL_SpecterApp");
lua_setmetatable(l, -2);
return 1;
}
And, in some other function that initializes the Lua stack.
luaL_Reg sSpecterAppRegs[] =
{
{ "create", l_SpecterApp_constructor },
{ NULL, NULL }
};
luaL_newmetatable(L, "luaL_SpecterApp");
luaL_register(L, NULL, sSpecterAppRegs);
lua_pushvalue(L, -1);
lua_setfield(L, -1, "__index");
lua_setglobal(L, "SpecterApp");
With this, A SpecterApp can be created from Lua as such:
local app = SpecterApp.create("An app",1280,720,true,60)