int
LuaStack::luaLoadBuffer(lua_State
*
L, const char
*
chunk,
int
chunkSize, const char
*
chunkName)
{
int
r
=
0
;
if
(_xxteaEnabled && strncmp(chunk, _xxteaSign, _xxteaSignLen)
=
=
0
)
{
/
/
decrypt XXTEA
xxtea_long
len
=
0
;
unsigned char
*
result
=
xxtea_decrypt((unsigned char
*
)chunk
+
_xxteaSignLen,
(xxtea_long)chunkSize
-
_xxteaSignLen,
(unsigned char
*
)_xxteaKey,
(xxtea_long)_xxteaKeyLen,
&
len
);
unsigned char
*
content
=
result;
xxtea_long contentSize
=
len
;
skipBOM((const char
*
&)content, (
int
&)contentSize);
r
=
luaL_loadbuffer(L, (char
*
)content, contentSize, chunkName);
free(result);
}
else
{
skipBOM(chunk, chunkSize);
r
=
luaL_loadbuffer(L, chunk, chunkSize, chunkName);
}
if
(r)
{
switch (r)
{
case LUA_ERRSYNTAX:
CCLOG(
"[LUA ERROR] load \"%s\", error: syntax error during pre-compilation."
, chunkName);
break
;
case LUA_ERRMEM:
CCLOG(
"[LUA ERROR] load \"%s\", error: memory allocation error."
, chunkName);
break
;
case LUA_ERRFILE:
CCLOG(
"[LUA ERROR] load \"%s\", error: cannot open/read file."
, chunkName);
break
;
default:
CCLOG(
"[LUA ERROR] load \"%s\", error: unknown."
, chunkName);
}
}
return
r;
}