Fixes some warnings in Lua manual bindings. (#15443)

1. Use __Type for deprecated classes.
2. Refactored LuaStack::luaLoadChunksFromZIP() and use FileUtils:getDataFromFile().
3. Fixes wrongly compare NULL with char array.
This commit is contained in:
xpol 2016-04-18 16:35:50 +08:00 committed by minggo
parent a667b4bf00
commit 24db45e925
2 changed files with 13 additions and 17 deletions

View File

@ -439,13 +439,13 @@ int LuaEngine::handleCommonEvent(void* data)
return 0;
CommonScriptData* commonInfo = static_cast<CommonScriptData*>(data);
if (NULL == commonInfo->eventName || 0 == commonInfo->handler)
if ('\0' == commonInfo->eventName[0] || 0 == commonInfo->handler)
return 0;
_stack->pushString(commonInfo->eventName);
if (NULL != commonInfo->eventSource)
{
if (NULL != commonInfo->eventSourceClassName && strlen(commonInfo->eventSourceClassName) > 0)
if ('\0' != commonInfo->eventSourceClassName[0])
{
_stack->pushObject(commonInfo->eventSource, commonInfo->eventSourceClassName);
}

View File

@ -25,6 +25,7 @@
#include "scripting/lua-bindings/manual/CCLuaStack.h"
#include "scripting/lua-bindings/manual/tolua_fix.h"
#include <string.h>
#include "external/xxtea/xxtea.h"
extern "C" {
#include "lua.h"
@ -623,7 +624,7 @@ int LuaStack::executeFunctionReturnArray(int handler,int numArgs,int numResults,
if (lua_type(_state, -1) == LUA_TBOOLEAN) {
bool value = lua_toboolean(_state, -1);
resultArray.addObject(__Bool::create(value)) ;
resultArray.addObject(__Bool::create(value));
}else if (lua_type(_state, -1) == LUA_TNUMBER) {
@ -808,29 +809,27 @@ int LuaStack::luaLoadChunksFromZIP(lua_State *L)
LuaStack *stack = this;
do {
ssize_t size = 0;
void *buffer = nullptr;
unsigned char *zipFileData = utils->getFileData(zipFilePath.c_str(), "rb", &size);
ZipFile *zip = nullptr;
Data zipFileData(utils->getDataFromFile(zipFilePath));
unsigned char* bytes = zipFileData.getBytes();
ssize_t size = zipFileData.getSize();
bool isXXTEA = stack && stack->_xxteaEnabled && zipFileData;
for (int i = 0; isXXTEA && i < stack->_xxteaSignLen && i < size; ++i) {
isXXTEA = zipFileData[i] == stack->_xxteaSign[i];
}
bool isXXTEA = stack && stack->_xxteaEnabled && size >= stack->_xxteaSignLen
&& memcmp(stack->_xxteaSign, bytes, stack->_xxteaSignLen) == 0;
if (isXXTEA) { // decrypt XXTEA
xxtea_long len = 0;
buffer = xxtea_decrypt(zipFileData + stack->_xxteaSignLen,
buffer = xxtea_decrypt(bytes + stack->_xxteaSignLen,
(xxtea_long)size - (xxtea_long)stack->_xxteaSignLen,
(unsigned char*)stack->_xxteaKey,
(xxtea_long)stack->_xxteaKeyLen,
&len);
free(zipFileData);
zipFileData = nullptr;
zip = ZipFile::createWithBuffer(buffer, len);
} else {
if (zipFileData) {
zip = ZipFile::createWithBuffer(zipFileData, size);
if (size > 0) {
zip = ZipFile::createWithBuffer(bytes, (unsigned long)size);
}
}
@ -879,9 +878,6 @@ int LuaStack::luaLoadChunksFromZIP(lua_State *L)
lua_pushboolean(L, 0);
}
if (zipFileData) {
free(zipFileData);
}
if (buffer) {
free(buffer);