The new version of the cocos2d-x uses luajit to replace the original lua, The first advantage is that it can greatly improve the running speed (android can open jit, running speed increased by 10 ~ 60 times. jit cannot be enabled in ios, and the running speed can be improved by 2 ~ 3 times ). Second, the bytecode compiled by luajit cannot be decompiled, that is, it cannot be cracked. Luajit is described in detail here. 1. Basic use. This is simple. You do not need to modify any code and it is fully compatible with lua5.1. Replace the corresponding header file and library with luajit (the same name as lua). 2. compile it into bytecode upon release. The execution file of luajit.exe. Compilation Method (windows ( http://luajit.org/download.html Download the source code and use the vs command line tool to execute msvc. bat for compilation. When I first started using cygwin to directly execute make, there were many compilation errors and strange problems. In fact, batch processing is the correct method. After compilation, the luajit.exe and source code src/jit folders must be used simultaneously and matched. Otherwise, the "unknown luaJIT command or jit. * modules not installed" error may occur during running. The command for compiling to bytecode is as follows: For more details about the output file of the original luajit-B file, you can directly execute luajit-B to obtain it. Note that it is best to keep the. lua extension for the output file. Otherwise, the file cannot be found during the require file. Unless the complete name is used in require. I also encountered a problem when compiling bytecode, that is, no matter what files are compiled, the system prompts "luajit '= 'expected near' <eof> '", later, I changed the luajit version and it didn't appear. It may be related to the luajit source code I initially failed to change. 3. The execution file used to compile the luajit static library file (for android) to compile the bytecode must be consistent with the static library file used for development. Files required for windows are generated during compilation and execution. Android compilation requires the use of NDK for cross-compilation in windows. Here, cygwin was not successfully used at the beginning. A lot of compilation errors. Later, mingw was a relatively smooth change. I am using the msys + mingw environment (installed with the msysgit ..) Compiling scripts refer to the cocos2d-x itself and the luajit official website. Modify as follows:
#!/bin/sh SRCDIR=/c/msysgit/msysgit/LuaJit-2.0.2 DIR=/d/MyProj/develop/lib/cocos2d-x/scripting/lua/luajit cd "$SRCDIR" NDK=/d/adt-bundle-windows/android-ndk-r8e NDKABI=8 NDKVER=$NDK/toolchains/arm-linux-androideabi-4.7 NDKP=$NDKVER/prebuilt/windows/bin/arm-linux-androideabi- NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-arm" #Android/ARM, armeabi (ARMv5TE soft-float), Android 2.2+ (Froyo) DESTDIR=$DIR/android/armeabi rm "$DESTDIR"/*.a make clean make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_SYS=Linux TARGET_FLAGS="$NDKF" if [ -f $SRCDIR/src/libluajit.a ]; then mv $SRCDIR/src/libluajit.a $DESTDIR/libluajit.a fi; # Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.0+ (ICS) NDKARCH="-march=armv7-a -Wl,--fix-cortex-a8" DESTDIR=$DIR/android/armeabi-v7a rm "$DESTDIR"/*.a make clean make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_SYS=Linux TARGET_FLAGS="$NDKF $NDKARCH" if [ -f $SRCDIR/src/libluajit.a ]; then mv $SRCDIR/src/libluajit.a $DESTDIR/libluajit.a fi; # Android/x86, x86 (i686 SSE3), Android 4.0+ (ICS) NDKABI=14 DESTDIR=$DIR/android/x86 NDKVER=$NDK/toolchains/x86-4.7 NDKP=$NDKVER/prebuilt/windows/bin/i686-linux-android- NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-x86" rm "$DESTDIR"/*.a make clean make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_SYS=Linux TARGET_FLAGS="$NDKF" if [ -f $SRCDIR/src/libluajit.a ]; then mv $SRCDIR/src/libluajit.a $DESTDIR/libluajit.a fi; make clean #!/bin/shSRCDIR=/c/msysgit/msysgit/LuaJit-2.0.2DIR=/d/MyProj/develop/lib/cocos2d-x/scripting/lua/luajitcd "$SRCDIR"NDK=/d/adt-bundle-windows/android-ndk-r8eNDKABI=8NDKVER=$NDK/toolchains/arm-linux-androideabi-4.7NDKP=$NDKVER/prebuilt/windows/bin/arm-linux-androideabi-NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-arm"#Android/ARM, armeabi (ARMv5TE soft-float), Android 2.2+ (Froyo)DESTDIR=$DIR/android/armeabirm "$DESTDIR"/*.amake cleanmake HOST_CC="gcc -m32" CROSS=$NDKP TARGET_SYS=Linux TARGET_FLAGS="$NDKF"if [ -f $SRCDIR/src/libluajit.a ]; then mv $SRCDIR/src/libluajit.a $DESTDIR/libluajit.afi;# Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.0+ (ICS)NDKARCH="-march=armv7-a -Wl,--fix-cortex-a8"DESTDIR=$DIR/android/armeabi-v7arm "$DESTDIR"/*.amake cleanmake HOST_CC="gcc -m32" CROSS=$NDKP TARGET_SYS=Linux TARGET_FLAGS="$NDKF $NDKARCH"if [ -f $SRCDIR/src/libluajit.a ]; then mv $SRCDIR/src/libluajit.a $DESTDIR/libluajit.afi;# Android/x86, x86 (i686 SSE3), Android 4.0+ (ICS)NDKABI=14DESTDIR=$DIR/android/x86NDKVER=$NDK/toolchains/x86-4.7NDKP=$NDKVER/prebuilt/windows/bin/i686-linux-android-NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-x86"rm "$DESTDIR"/*.amake cleanmake HOST_CC="gcc -m32" CROSS=$NDKP TARGET_SYS=Linux TARGET_FLAGS="$NDKF"if [ -f $SRCDIR/src/libluajit.a ]; then mv $SRCDIR/src/libluajit.a $DESTDIR/libluajit.afi;
Make clean first sets SRCDIR and DIR, which are the directory of Luajit source code and the installation directory of compiled library files. The NDK specifies the installation directory of android ndk. The original cocos2d-x script automatically detects host (related to this line of code NDKP = $ NDKVER/prebuilt/windows/bin/arm-linux-androideabi-), but not very useful, therefore, we need to modify it to windows. When compiling armv7a, the minilua.exe execution error always exists and cannot be compiled successfully. After removing-mfloat-abi = softfp, the compilation is normal.