这个是在昨天修改之后发现每次执行python后会被覆盖,所以今天将那部分代码提取出来
我发现每次执行python后 lua_cocos2dx_cocosbuilder_manual.cpp 并不会被覆盖,所以我将新加的文件放在这个文件的register_cocosbuilder_module方法中,
其实如果以后还是会被覆盖,那不如直接放进LuaStack.cpp里吧
1.首先添加lua_cocos2dx_cocosbuilder_ex.h 和cpp文件吧,目录我是放在lua_cocos2dx_cocosbuilder_manual同目录下
lua_cocos2dx_cocosbuilder_ex.h
#ifdef __cplusplus
extern "C" {
#endif
#include "tolua++.h"
#ifdef __cplusplus
}
#endif
int register_all_cocos2dx_cocosbuilder_ex(lua_State* tolua_S);
lua_cocos2dx_cocosbuilder_ex.cpp
#include "lua_cocos2dx_cocosbuilder_ex.h"
#include "CocosBuilder.h"
#include "tolua_fix.h"
#include "LuaBasicConversions.h"
#include "CCLuaEngine.h"
#include "scripting/lua-bindings/manual/cocosbuilder/LuaCCBAnimationWrapper.h"
USING_NS_CC;
USING_NS_CC_EXT;
/* method: setAnimationCompletedCallback of class CCBAnimationManager */
static int tolua_cocos2d_CCBAnimationManager_setAnimationCompletedCallback(lua_State* tolua_S)
{
if (NULL == tolua_S)
return 0;
int argc = 0;
cocosbuilder::CCBAnimationManager* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"cc.CCBAnimationManager",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_CCBAnimationManager_setAnimationCompletedCallback'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 1)
{
#if COCOS2D_DEBUG >= 1
if(!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err))
goto tolua_lerror;
#endif
LUA_FUNCTION handler = toluafix_ref_function(tolua_S,2,0);
//ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::NODE);
LuaCCBAnimationWrapper* tmpCallback = new LuaCCBAnimationWrapper();
tmpCallback->setCallback(handler);
self->setAnimationCompletedCallback(tmpCallback, CC_CALLFUNC_SELECTOR(LuaCCBAnimationWrapper::animationCompletedCallback));
return 0;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n", "cc.CCBAnimationManager:setAnimationCompletedCallback",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'tolua_cocos2d_CCBAnimationManager_setAnimationCompletedCallback'.",&tolua_err);
return 0;
#endif
}
int lua_register_cocos2dx_cocosbuilder_ex(lua_State* tolua_S)
{
tolua_usertype(tolua_S,"cc.CCBAnimationManager");
tolua_cclass(tolua_S,"CCBAnimationManager","cc.CCBAnimationManager","cc.Ref",nullptr);
tolua_beginmodule(tolua_S,"CCBAnimationManager");
tolua_function(tolua_S, "setAnimationCompletedCallback", tolua_cocos2d_CCBAnimationManager_setAnimationCompletedCallback);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocosbuilder::CCBAnimationManager).name();
g_luaType[typeName] = "cc.CCBAnimationManager";
g_typeCast["CCBAnimationManager"] = "cc.CCBAnimationManager";
return 1;
}
TOLUA_API int register_all_cocos2dx_cocosbuilder_ex(lua_State* tolua_S)
{
tolua_open(tolua_S);
tolua_module(tolua_S,"cc",0);
tolua_beginmodule(tolua_S,"cc");
lua_register_cocos2dx_cocosbuilder_ex(tolua_S);
tolua_endmodule(tolua_S);
return 1;
}
2.在lua_cocos2dx_cocosbuilder_manual.cpp中加入
int register_cocosbuilder_module(lua_State* tolua_S)
{
lua_getglobal(tolua_S, "_G");
if (lua_istable(tolua_S,-1))//stack:...,_G,
{
register_all_cocos2dx_cocosbuilder(tolua_S);
register_all_cocos2dx_cocosbuilder_manual(tolua_S);
register_all_cocos2dx_cocosbuilder_ex(tolua_S);
}
lua_pop(tolua_S, 1);
return 1;
}
3.写的较粗糙,其余步骤参考上一篇文章即可