I'm taking a look at luajit. I'd like to learn how to properly use it to speed up my code. I know how to use its FFI extension but I'd like to know how to work with its bytecode exporter.
Why would you export a lua file? Is that even possible?
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).
LuaJIT is a JIT compiler (just-in time compiler). That means it doesn't do any compilation/optimizations to your code until it's already running.
Exporting code to a LuaJIT bytecode file just makes it marginally easier for LuaJIT to initially load the code, it won't speed it up any more than it already does for plain Lua code - all of the performance-related aspects of LuaJIT happen automatically at runtime even with plain Lua source code.
I knew what a JIT compiler is. Was just wondering about the bytecode. Thank you
So the only only simple speedup I can do apart from running my code with LuaJIT is to use its FFI interface when possible and replace some of the stuff with C types right?
Not compile to a lua file, but compile to Raw bytecode file and can be used as a lua file.
raw or any other extension — Raw bytecode file (portable).
Named without .lua, OK.
.c : A c source file, can be open with text editor. The bytecode is shown as a char *. Maybe used in C.
.h : Almost the same as .c, but used as a c header file.
.o, .obj : No clue. I can't run it with luajit.
The advantages of using bytecode compare to source file:
1. no string parse
2. protect source code to a certain extent
padicao2010 wrote:Not compile to a lua file, but compile to Raw bytecode file and can be used as a lua file.
raw or any other extension — Raw bytecode file (portable).
Named without .lua, OK.
.c : A c source file, can be open with text editor. The bytecode is shown as a char *. Maybe used in C.
.h : Almost the same as .c, but used as a c header file.
.o, .obj : No clue. I can't run it with luajit.
The advantages of using bytecode compare to source file:
1. no string parse
2. protect source code to a certain extent
.o is basically a "partial executable" (OS dependent, native) that you can link to when compiling another file to include the lua module so it can be require'd if I understand the docs correctly.