cocos2dx 3.13
自动生成的lua接口代码传string到lua时不支持含0的字符串。修复方法:
int lua_myproj_CustomLuaEvent_getStrData(lua_State* tolua_S)
{
int argc = 0;
CustomLuaEvent* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"CustomLuaEvent",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (CustomLuaEvent*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_myproj_CustomLuaEvent_getStrData'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_myproj_CustomLuaEvent_getStrData'", nullptr);
return 0;
}
std::string ret = cobj->getStrData();
//---------------------------------------------------------------------------------
//tolua_pushcppstring(tolua_S,ret); // not suport cpp std::string (contains 0x00)
// 修改为
if (ret.empty())
lua_pushnil(tolua_S);
else
lua_pushlstring(tolua_S, ret.c_str(), ret.size());
//---------------------------------------------------------------------------------
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "CustomLuaEvent:getStrData",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_myproj_CustomLuaEvent_getStrData'.",&tolua_err);
#endif
return 0;
}