I'm currently using OpenResty + Lua for several projects, and I like the flexibility that Lua gives me, in fact I wrote some micro-web apps directly in Lua scripts, that are served by Nginx-OpenResty.
But, if I want to distribute the web app, obviously the Lua code should be either "plain" or, at least, slightly obfuscated. Instead, considering that LuaJIT that I'm currently using compiles Lua to native code, is it possible to pre-compile all Lua scripts as native code (not lua .o object files), and load them in OpenResty, instead of direct .lua source files?
Nope.
There's no way to compile LuaJIT code to machine code. It simply doesn't work that way, for two main reasons:
if
branches can be compiled depending on which one is taken more often). Thus, it's impossible to precompile them ahead of time.require
), or because it's simply not possible (ex. calls to Lua C API functions)Your best bet is to compile the Lua files to LuaJIT bytecode with the debugging info stripped instead. This means stuff like local variable names, line numbers, etc. are omitted, but can still be disassembled.