24,854
社区成员
发帖
与我相关
我的任务
分享
我在C++中调用lua中表的函数
lua_getglobal(m_state, tableName); /* query function by name, stack: function */
if(!lua_istable(m_state,-1))
{
// CCLOG("[LUA ERROR] %s is not a table",tableName);
return 0;
}
lua_pushfstring(m_state,functionName);
lua_gettable(m_state,-2);
if (!lua_isfunction(m_state,-1))
{
// CCLOG("[LUA ERROR] %s is not a table.Function",functionName);
return 0;
}
/////////怎么把默认的self传进去?
int error = lua_pcall(m_state, nargs, nresults, errfunc);
if (error)
{
CCLOG("[LUA ERROR] %s", lua_tostring(m_state, - 1));
lua_settop(m_state, 0);
return 0;
}
int iRet=1;
if (lua_isboolean(m_state, -1))
{
bool bRet = lua_toboolean(m_state, -1);
if (bRet)
{
iRet= RET_CALLPARENT;
return iRet;
}
}
lua_pop(m_state, 1);