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)”