mirror of https://github.com/axmolengine/axmol.git
Merge pull request #9919 from edwardzhou/luaLoadChunksFromZIP_supports_folder_structured_lua
Lua load chunks from zip supports folder structured lua
This commit is contained in:
commit
42b6fbd1c6
|
@ -842,6 +842,19 @@ int LuaStack::luaLoadChunksFromZIP(lua_State *L)
|
|||
ssize_t bufferSize = 0;
|
||||
unsigned char *zbuffer = zip->getFileData(filename.c_str(), &bufferSize);
|
||||
if (bufferSize) {
|
||||
// remove extension
|
||||
std::size_t found = filename.rfind(".lua");
|
||||
if (found != std::string::npos)
|
||||
{
|
||||
filename.erase(found);
|
||||
}
|
||||
// replace path seperator '/' '\' to '.'
|
||||
for (int i=0; i<filename.size(); i++) {
|
||||
if (filename[i] == '/' || filename[i] == '\\') {
|
||||
filename[i] = '.';
|
||||
}
|
||||
}
|
||||
CCLOG("[luaLoadChunksFromZIP] add %s to preload", filename.c_str());
|
||||
if (stack->luaLoadBuffer(L, (char*)zbuffer, (int)bufferSize, filename.c_str()) == 0) {
|
||||
lua_setfield(L, -2, filename.c_str());
|
||||
++count;
|
||||
|
|
Loading…
Reference in New Issue