cocos2d-x3.x我自定义一个类并导出这个类,这个类提供一个方法给Lua,作用是注册一个function给C++,让C++能调用Lua的这个方法。
类似CallFunc:create(function()end)这样。
但是目前3.x的tolua工具都没提供一个方法可以转出类似这样的函数,请教有何解决办法?
【已解决】
我后来是参考了cocos/scripting\lua-bindings\manual\cocos2d 下的手动binding.
cocos2d-x3.x我自定义一个类并导出这个类,这个类提供一个方法给Lua,作用是注册一个function给C++,让C++能调用Lua的这个方法。
类似CallFunc:create(function()end)这样。
但是目前3.x的tolua工具都没提供一个方法可以转出类似这样的函数,请教有何解决办法?
【已解决】
我后来是参考了cocos/scripting\lua-bindings\manual\cocos2d 下的手动binding.
参考
http://blog.sina.com.cn/s/blog_93add5520101lv02.html
http://www.cocoachina.com/bbs/read.php?tid-293492.html
http://www.cnblogs.com/emyueguang/p/3713684.html
那样搞太麻烦,最简单就是直接传入一个CallFunc对象作为回调对象,把CallFunc保留下来,调用的时候直接调用CallFunc->execute方法就搞定了,简单有效
我原来 2.x 版本的时候 是这么做的
大概这么一个 函数
void LuaHandleMgr::registerHandle2COnKey( LUA_FUNCTION handle, const std::string& strKey )
{
if ( strKey.empty() )
{
return;
}
m_mHandle.insert( std::make_pair( strKey, handle ) );
}
LUA_FUNCTION LuaHandleMgr::getHandleByKey( const std::string& strKey )
{
mList::const_iterator cit = m_mHandle.find( strKey );
if ( cit != m_mHandle.end() )
{
return cit->second;
}
return 0;
}
不过 现在用的3.6 的版本 发现 LUA_FUNC 绑定不进lua 因为 要检查头文件 最后lua.h 通不过
才用的这种方法
已解决,感谢各位回复!!