In C ++ code:
class CWindowUI { public CWindowUI(const char* title,int width,int height); ..... }; static int CreateWindow(lua_State *l) { int width,height; char *title; CWindowUI **winp, *win; name = (char *) luaL_checkstring(l, 1); width= lua_tounsigned(l, 2); height= lua_tounsigned(l, 3); win = new CWindowUI(title,width,height); if (win == NULL) { lua_pushboolean(l, 0); return 1; } winp = (CWindowUI **) lua_newuserdata(l, sizeof(CWindowUI *)); luaL_getmetatable(l, "WindowUI"); lua_setmetatable(l, -2); *winp = win; return 1; }
In the Lua code:
local win = CreateWindow("title", 480, 320); win:resize(800, 600);
Now my question is:
The CreateWindow will return an object named win , and the resize function is undefined. How to get notified when I call undefined function in Lua?
The notification must contain the string "resize" and arguments 800,600 . I want to change the source to map the undefined function to a callback function, but it is incorrect.
source share