cocos2dx android运行Luac编译后的lua代码

环境:android

win7 64windows

cocos2d-2.1rc0-x-2.1.2app

lua 5.1加密

 

  一般咱们编写好的lua代码都是明文形式,谁均可以查看修改,为了防止本身的劳动成果不被别人轻易的盗取,能够使用luac(lua库中自带)对其进行加密,转换为二进制文件。这样lua代码就没法直接查看,可是这里会有一个问题:在windows下可以很好的运行,在android上就会黑屏,提示错误:lua

[LUA ERROR] binary string: unexpected end in precompiled chunkspa

 

追根溯源code

  在bool AppDelegate::applicationDidFinishLaunching()中查看lua加载代码:blog

 1 #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
 2     CCString* pstrFileContent = CCString::createWithContentsOfFile( "program/main.lua" );
 3     if (pstrFileContent)
 4     {
 5         pEngine->executeString(pstrFileContent->getCString());
 6     }
 7 #else        
 8     std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename( "program/main.lua" );
 9     pEngine->addSearchPath( path.substr( 0, path.find_last_of( "/" ) ).c_str() );
10     pEngine->executeScriptFile( path.c_str() );
11 #endif

 

  这里用的是executeString()方法来加载lua文件,查看源码发现:ip

1 LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s) {
2     printf("%s", s);
3   return luaL_loadbuffer(L, s, strlen(s), s);
4 }

 

dget

相关文章
相关标签/搜索