大佬教程收集整理的这篇文章主要介绍了cocos2dxandroid运行Luac编译后的lua代码,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
运行环境
win7 64
cocos2d-2.1rc0-x-2.1.2
lua 5.1
通常我们编写好的lua代码都是明文形式,谁都可以查看修改,为了防止自己的劳动成果不被别人轻易的盗取,可以使用luac(lua库中自带)对其进行加密,转换为二进制文件。这样lua代码就无法直接查看,但是这里会有一个问题:在windows下能够很好的运行,@R_489_5313@d上就会黑屏,提示错误:
[LUA ERROR] binary String: unexpected end in precompiled chunk
追根溯源
在bool AppDelegate::applicationDidFinishLaunching()中查看lua加载代码:
01.
#
if
(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
03.
if
(pstrFileContent)
04.
{
06.
}
07.
#
else
11.
#endif
02.
LoadF lf;
03.
int
status,readstatus;
04.
int
c;
05.
int
fnameindex = lua_gettop(L) +
1
;
/* index of filename on the stack */
06.
lf.extraline =
0
;
08.
lua_pushliteral(L,
"=stdin"
);
09.
lf.f = stdin;
10.
}
11.
else
{
14.
if
(lf.f == NULL)
return
errfile(L,
"open"
,fnameindeX);
15.
}
16.
c = getc(lf.f);
17.
if
(c ==
'#'
) {
/* Unix exec. file? */
18.
lf.extraline =
1
;
20.
') ;
/* skip first line */
21.
if
(c == '
22.
') c = getc(lf.f);
23.
}
26.
if
(lf.f == NULL)
return
errfile(L,
"reopen"
,fnameindeX);
27.
/* skip eventual `#!...' */
29.
lf.extraline =
0
;
30.
}
31.
ungetc(c,lf.f);
33.
readstatus = ferror(lf.f);
35.
if
(readstatus) {
36.
lua_settop(L,fnameindeX);
/* ignore results from `lua_load' */
37.
return
errfile(L,
"read"
,fnameindeX);
38.
}
39.
lua_remove(L,fnameindeX);
40.
return
status;
41.
}
解决办法
修改scripTingluacocos2dx_supportCocos2dxLuaLoader.cpp中的loader_Android()函数
修改前:
01.
int
loader_Android(lua_State* L)
02.
{
03.
unsigned
char
* PDAta = nullptr;
04.
unsigned
long
size =
0
;
05.
06.
/* modify for read lua script from bytecode */
07.
std::string filename(luaL_checkString(L,rel_name.c_str()) !=
0
|| lua_pcall(L,
0
,LUA_MULTRET,
0
) ) {
// 修改处
19.
}
20.
22.
23.
return
1
;
24.
}
最后我们的AppDelegate::applicationDidFinishLaunching()大概就是这样的,
注:这里笔者偷鸡了一下。
以上是大佬教程为你收集整理的cocos2dxandroid运行Luac编译后的lua代码全部内容,希望文章能够帮你解决cocos2dxandroid运行Luac编译后的lua代码所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。