我正在尝试在 Lua 中注册一个 C++ 函数。
但出现此错误:
CScript.cpp|39|error: argument of type 'int (CScript::)(lua_State*)' does not match 'int (*)(lua_State*)'|
EDIT:
int CApp::SetDisplayMode(int Width, int Height, int Depth)
{
this->Screen_Width = Width;
this->Screen_Height = Height;
this->Screen_Depth = Depth;
return 0;
}
int CScript::Lua_SetDisplayMode(lua_State* L)
{
// We need at least one parameter
int n = lua_gettop(L);
if(n < 0)
{
lua_pushstring(L, "Not enough parameter.");
lua_error(L);
}
int width = lua_tointeger(L, 1);
int height = lua_tointeger(L, 2);
int depth = lua_tointeger(L, 3);
lua_pushinteger(L, App->SetDisplayMode(width, height, depth));
return 0;
}
主要是:
lua_register(L, "setDisplayMode", Lua_SetDisplayMode);
除非声明了类的方法,否则不能将其用作普通函数static
。你必须定义一个普通的函数,它找出你想要在哪个对象中调用该方法,然后调用该方法。
无法使用类方法作为 C 函数的回调(请记住 Lua API 是纯 C 库)的主要原因是计算机不知道应该在哪个对象上调用该方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)