在 C++ 代码中:
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;
}
在 Lua 代码中:
local win = CreateWindow("title", 480, 320);
win:resize(800, 600);
现在我的问题是:
函数CreateWindow
将返回一个名为win
且函数resize
未定义的对象。在 Lua 中调用未定义函数时如何获得通知?
通知应包括字符串"resize"
和参数800,600
。我想修改源以将未定义的函数映射到回调函数,但它不正确。