怎样使用Cocos LUACompile

原文地址:http://www.cocos2d-x.org/wiki/Cocos_luacompile


怎样使用Cocos LUACompile

  • 怎样使用cocos luacompile
    • 预览
    • 环境设置
    • 使用方法
    • 可用的参数
    • 例子

预览

将 .lua 文件编译为 .luac 所涉及到的加密方法

环境配置

如果是cocos2d-x V3.3 或者更高级的版本, 你需要配置 cocos consol(请查看 https://github.com/cocos2d/cocos2d-x/blob/v3/README.md)

如果版本是cocos2d-x V2.2.6, 你应该安装 Python, 然后设置Python的环境变量.

使用方法

如果是cocos2d-x V3.3 或者更高级的版本, 在终端里输入 cocos luacompile [arguments]

如果版本是cocos2d-x V2.2.6, 在终端里,首先 cd 进目录tools/cocos2d-console/console, 然后输入 ./cocos2d.py luacompile [arguments] .

可用的参数(在终端里)

参数 参数的值 例子 描述 是否必须
-h, --help - - Show the help message and exit no
-v, --verbose - - verbose output no
-s, --src source directory ./projects/MyLuaGame/src Specify source directory of lua files needed to be compiled,support mutiple source directory yes
-d, --dst destination directory ./projects/MyLuaGame/dst Specify destination directory which bytecode files to be stored. yes
-e, --encrypt bool True Whether or not to encrypt lua files. no
-k, --encryptkey any string MyLuaKey Specify the encrypt key for encrypting lua scripts. It's only take effect when -e, --encrypt is enabled. Default value is 2dxLua. no
-b, --encryptsign any string MyLuaSign Specify the encrypt sign for encrypting lua scripts. It's only take effect when --encrypt is enabled. Default value is XXTEA. no
--disable-compile bool True Whether or not to compile lua scripts no

例子

 使用luacompile时,有以下几种方式

方式 cocos2d-x 版本 描述
cocos luacompile -h cocos2d-x V3.3 or higher version Show the help message
cocos luacompile -s src_dir -d dst_dir cocos2d-x V3.3 or higher version Precompile the Lua files in the src_dir directory to bytecode files which luajit supports, then store them in the dst_dir directory by the same directory structure.
cocos luacompile -s src_dir -d dst_dir -e True cocos2d-x V3.3 or higher version Precompile the Lua files in the src_dir directory to bytecode files which luajit supports, then encrypt this bytecoed files by xxtea.The key and sign for encrypting are 2dxLuaand XXTEA by default. By adding  -k xxx -b xxx' to the command, developers can change thekeyandsign,-k xxxset the key value and-b xxx` set the sign value. The encrypted files are stored in the dst_dir directory by the same directory structure.
cocos luacompile -s src_dir -d dst_dir -e True --disable-compile True cocos2d-x V3.3 or higher version Encrypt the Lua files in the src_dir by xxtea, then store them in the dst_dir directory by the same directory structure. The key and sign for encrypting are 2dxLua and XXTEA by default. By adding  -k xxx -b xxx' to the command, developers can change thekeyandsign,-k xxxset the key value and-b xxx` set the sign value. This command is mainly used to make a set of encrypted files run both 32bit and 64bit iOS devices at the same time. Because Apple demand new app must support 64bit,but the stable luajit doesn't support the arm64bit, so providing this command to encrypt the lua files directly.
./cocos2d.py luacompile -h cocos2d-x V2.2.6 Show the help message
./cocos2d.py luacompile -s src_dir -d dst_dir cocos2d-x V2.2.6 Precompile the Lua files in the src_dir directory to bytecode files which luajit supports, then store them in the dst_dir directory by the same directory structure.
./cocos2d.py luacompile -s src_dir -d dst_dir -e True cocos2d-x V2.2.6 Precompile the Lua files in the src_dir directory to bytecode files which luajit supports, then encrypt this bytecoed files by xxtea.TThe key and sign for encrypting are 2dxLua and XXTEA by default. By adding  -k xxx -b xxx' to the command, developers can change thekeyandsign,-k xxxset the key value and-b xxx` set the sign value. The encrypted files are stored in the dst_dir directory by the same directory structure.
./cocos2d.py luacompile -s src_dir -d dst_dir -e True --disable-compile True cocos2d-x V2.2.6 Encrypt the Lua files in the src_dir by xxtea, then store them in the dst_dir directory by the same directory structure. The key and sign for encrypting are 2dxLua and XXTEA by default, by adding  -k xxx -b xxx' to the command, developers can change thekeyandsign,-k xxxset the key value and-b xxx` set the sign value. This command is mainly used to make a set of encrypted files run both 32bit and 64bit iOS devices at the same time.

注意: 如果在游戏里使用了xxtea加密,你必须调用在c++代码里,调用LuaStack里的setXXTEAKeyAndSign方法以设置key和sign来解密文件。

你可能感兴趣的:(怎样使用Cocos LUACompile)