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:
minggo 2015-01-23 16:13:09 +08:00
commit 42b6fbd1c6
1 changed files with 13 additions and 0 deletions

View File

@ -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;