lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


HyperHacker <hyperhacker <at> gmail.com> writes:
> I was just wondering to myself if LuaJIT could ever be hacked to
> function as a Lua compiler, that compiles scripts to standalone
> executables or libraries.

By "standalone executable" do you mean:

1. one that embeds the LuaJIT and the Lua program, or
2. one that contains machine code for the original Lua program,
   but not LuaJIT or Lua program itself.

(1) is not very difficult.

(2) is not feasible, AIUI.  LuaJIT can only generate fast code
when it can observe runtime traces.  These traces are not
something that can be generated ahead-of-time, because they
depend on eg. the actual types of variables.  Even if they could
be generated ahead-of-time, the runtime profile of the program
could change as it is running; a tracing JIT can adapt to this,
but AOT compiling could not, which would compromise performance.

Also, since the slow paths of the JIT-ted code fall back to
the interpreter, you'd have to include LuaJIT's interpreter in
the standalone executable.

Josh