怎么使用tolua++在C++中调用lua中表的函数

arabicsara 2012-10-09 11:03:34
我在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);

如lua中的function p:OnInitDialog() 这个函数,但是这个函数里面不能使用self,self变成nil了,请问要怎么把self也传进来?
function p:OnInitDialog()
assert(self) --调用到这里就错了
...全文
179 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
冷月清晖 2012-10-10
  • 打赏
  • 举报
回复
图灵狗 2012-10-09
  • 打赏
  • 举报
回复
参考这篇(http://hi.baidu.com/gingber/item/34d151c13be5022b46d5c0f5)文章,特别关注nSelf相关的代码。

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧