cocos2dx android运行Luac编译后的lua代码
2014-05-14 09:23
543 查看
环境:
win7 64
cocos2d-2.1rc0-x-2.1.2
lua 5.1
通常我们编写好的lua代码都是明文形式,谁都可以查看修改,为了防止自己的劳动成果不被别人轻易的盗取,可以使用luac(lua库中自带)对其进行加密,转换为二进制文件。这样lua代码就无法直接查看,但是这里会有一个问题:在windows下能够很好的运行,在android上就会黑屏,提示错误:
[LUA ERROR] binary string: unexpected end in precompiled chunk
追根溯源
在bool AppDelegate::applicationDidFinishLaunching()中查看lua加载代码:
这里用的是executeString()方法来加载lua文件,查看源码发现:
d
win7 64
cocos2d-2.1rc0-x-2.1.2
lua 5.1
通常我们编写好的lua代码都是明文形式,谁都可以查看修改,为了防止自己的劳动成果不被别人轻易的盗取,可以使用luac(lua库中自带)对其进行加密,转换为二进制文件。这样lua代码就无法直接查看,但是这里会有一个问题:在windows下能够很好的运行,在android上就会黑屏,提示错误:
[LUA ERROR] binary string: unexpected end in precompiled chunk
追根溯源
在bool AppDelegate::applicationDidFinishLaunching()中查看lua加载代码:
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) CCString* pstrFileContent = CCString::createWithContentsOfFile( "program/main.lua" ); if (pstrFileContent) { pEngine->executeString(pstrFileContent->getCString()); } #else std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename( "program/main.lua" ); pEngine->addSearchPath( path.substr( 0, path.find_last_of( "/" ) ).c_str() ); pEngine->executeScriptFile( path.c_str() ); #endif
这里用的是executeString()方法来加载lua文件,查看源码发现:
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) { printf("%s", s); return luaL_loadbuffer(L, s, strlen(s), s); }
d
相关文章推荐
- 【COCOS2DX-LUA 脚本开发之十四】解决自定义CPP类通过TOLUA++ BINDING LUACOCOS2D后编译到ANDROID运行黑屏(没有调用自定义CPP类)的问题!
- 编译类【COCOS2DX-LUA 脚本开发之十四】解决自定义CPP类通过TOLUA++ BINDING LUACOCOS2D后编译到ANDROID运行黑屏(没有调用自定义CPP类)的问题!
- 【iOS-cocos2d-X 游戏开发之七】整合Cocos2dX的Android项目到Xcode项目中,Xcode编写&编译代码,Android导入打包运行即可!
- 【COCOS2DX-LUA 脚本开发之十四】解决自定义cpp类通过tolua++ binding LuaCocos2d后编译到Android运行黑屏(没有调用自定义cpp类)的问题!
- cocos2dx最新2.1.5版本跨平台整合NDK+Xcode,Xcode编写&编译代码,Android导入打包运行
- 【COCOS2DX-LUA 脚本开发之十四】解决自定义CPP类编译到ANDROID运行黑屏的问题!
- 【COCOS2DX-LUA 脚本开发之十四】解决自定义CPP类通过TOLUA++ BINDING LUACOCOS2D后编译到ANDROID运行黑屏(没有调用自定义CPP类)的问题!
- iOS-cocos2d-X 游戏开发之七】整合Cocos2dX的Android项目到Xcode项目中,Xcode编写&编译代码,Android导入打包运行即可!
- 【Cocos2d-X(2.x) 游戏开发系列之二】cocos2dx最新2.0.1版本跨平台整合NDK+Xcode,Xcode编写&编译代码,Android导入打包运行即可!
- 在EeePC上运行Android!(转)(也是代码下载配置编译的流程!)
- 【COCOS2DX-LUA 脚本开发之十三】解决lua项目编译Android出现get data from file failed以及路径等问题
- 编译在G1上运行的android 2.2(froyo)代码_正规版
- Learning Lua Programming (3) iMac下搭建Lua脚本最好的编码环境(代码补全,编译运行)
- 带自定义类的Cocos2dx_lua项目编译到Android
- 编译在N1(G5, Passion)上运行的姜饼(GingerBread,Android 2.3)代码
- 编译在G1上运行的android 2.2(froyo)代码_山寨版
- 整合Cocos2dX的Android项目到Xcode项目中,Xcode编写&编译代码
- cocos2dx在windows下编译运行移植android项目
- 【COCOS2DX-LUA 脚本开发之十三】解决lua项目编译Android出现get data from file failed、Cocos2dxActivity cannot be 路径等问题
- 编译在G1上运行的android 2.2(froyo)代码_正规版