LuaJIT Running
1.Configuring LuaJIT
The standard configuration should work fine for most installations. Usually there is no need to tweak the settings. The following files hold all user-configurable settings:
src/luaconf.h sets some configuration variables.
Makefile has settings for installing LuaJIT (POSIX only).
src/Makefile has settings for compiling LuaJIT under POSIX, MinGW or Cygwin.
src/msvcbuild.bat has settings for compiling LuaJIT with MSVC or WinSDK.
tar zxf LuaJIT-2.0.2.tar.gz
cd LuaJIT-2.0.2
make PREFIX=/soft/luajit
make install PREFIX=/soft/luajit
Cross-compiling LuaJIT
If you want to cross-compile to any 32 bit target on an x64 OS, you need to install the multilib development package (libc6-dev-i386 on Debian/Ubuntu) and build a 32 bit host part (HOST_CC="gcc -m32").
# Cross-compile to a 32 bit binary on a multilib x64 OS
make CC="gcc -m32"
# Cross-compile on Debian/Ubuntu for Windows (mingw32 package)
make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
2.Running LuaJIT
The luajit stand-alone executable is just a slightly modified version of the regular lua stand-alone executable. It supports the same basic options, too.
luajit -h prints a short list of the available options.
-b[options] input output
LuaJIT has some additional options:
-b[options] input output
This option saves or lists bytecode. The following additional options are accepted:
-l — Only list bytecode.
-s — Strip debug info (this is the default).
-g — Keep debug info.
-n name — Set module name (default: auto-detect from input name)
-t type — Set output file type (default: auto-detect from output name).
-a arch — Override architecture for object files (default: native).
-o os — Override OS for object files (default: native).
-e chunk — Use chunk string as input.
- (a single minus sign) — Use stdin as input and/or stdout as output.
The output file type is auto-detected from the extension of the output file name:
c — C source file, exported bytecode data.
h — C header file, static bytecode data.
obj or o — Object file, exported bytecode data (OS- and architecture-specific).
raw or any other extension — Raw bytecode file (portable).
Typical usage examples:
luajit -b test.lua test.out # Save bytecode to test.out
luajit -bg test.lua test.out # Keep debug info
luajit -be "print('hello world')" test.out # Save cmdline script
luajit -bl test.lua # List to stdout
luajit -bl test.lua test.txt # List to test.txt
luajit -ble "print('hello world')" # List cmdline script
luajit -b test.lua test.obj # Generate object file
# Link test.obj with your application and load it with require("test")
-j cmd[=arg[,arg...]]
Here are the available LuaJIT control commands:
-jon — Turns the JIT compiler on (default).
-joff — Turns the JIT compiler off (only use the interpreter).
-jflush — Flushes the whole cache of compiled code.
-jv — Shows verbose information about the progress of the JIT compiler.
-jdump — Dumps the code and structures used in various compiler stages.
The -jv and -jdump commands are extension modules written in Lua. They are mainly used for debugging the JIT compiler itself.