Cocos2d-x 3.17 热更新后addSearchPath找不到文件

extern "C"
{
    int cocos2dx_lua_loader(lua_State *L)
    {
        static const std::string BYTECODE_FILE_EXT    = ".luac";
        static const std::string NOT_BYTECODE_FILE_EXT = ".lua";

        std::string filename(luaL_checkstring(L, 1));
        size_t pos = filename.rfind(BYTECODE_FILE_EXT);
        if (pos != std::string::npos && pos == filename.length() - BYTECODE_FILE_EXT.length())
            filename = filename.substr(0, pos);
        else
        {
            pos = filename.rfind(NOT_BYTECODE_FILE_EXT);
            if (pos != std::string::npos && pos == filename.length() - NOT_BYTECODE_FILE_EXT.length())
                filename = filename.substr(0, pos);
        }

        pos = filename.find_first_of('.');
        while (pos != std::string::npos)
        {
            filename.replace(pos, 1, "/");
            pos = filename.find_first_of('.');
        }
}

修改后面的代码:

        if (filename.find("ark_update") == filename.npos)
		{
			pos = filename.find_first_of(".");
			while (pos != std::string::npos)
			{
				filename.replace(pos, 1, "/");
				pos = filename.find_first_of(".");
			}
		}else
		{
			CCLOG("filename is==%s",filename.c_str());
		}
  • 注:string::npos参数

string::npos参数: npos是一个常数,用来表示不存在的位置,npos定义的类型是: string::size_type。

  • npos定义为:static const size_type npos=-1;  //定义
  • 但是string::npos作为string的成员函数的一个长度参数时,表示“直到字符串结束(until the end of the string)”
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值