Question

Can MetaLua be used with LuaJIT?

And if it so, then how?

(I couldn't find any reliable info)

Was it helpful?

Solution

The Metalua compiler appears to be written in Lua and Metalua, so theoretically yes. The makefile reveals some of the interesting core pieces. Metalua itself appears to run on top of Lua.

cat > ${BUILD_BIN}/metalua <<EOF
#!/bin/sh
export LUA_PATH='?.luac;?.lua;${BUILD_LIB}/?.luac;${BUILD_LIB}/?.lua'
export LUA_MPATH='?.mlua;${BUILD_LIB}/?.mlua'
${LUA} ${BUILD_LIB}/metalua.luac \$*
EOF

However, LuaJIT isn't capable of compiling multiple scripts into one output file at the command line like LuaC. Simply replacing LUAC with an instance of LuaJIT won't do. The following lines will have to be adjusted for a LuaJIT-compatible makefile.

${LUAC} -o ${BUILD_LIB}/metalua/bytecode.luac lopcodes.lua lcode.lua ldump.lua compile.lua
${LUAC} -o ${BUILD_LIB}/metalua/mlp.luac lexer.lua gg.lua mlp_lexer.lua mlp_misc.lua mlp_table.lua mlp_meta.lua mlp_expr.lua mlp_stat.lua mlp_ext.lua

Unfortunately, that issue pales in comparison to the contents of some of the files that get compiled into bytecode.luac, considering that they reference PUC-Lua opcodes and bytecode, which are definitely incompatible with LuaJIT.

I'd say that if it is possible, then it would certainly require some reprogramming of the compiler, but out-of-the-box usage with LuaJIT is highly unlikely.

OTHER TIPS

The answer depends on what you are trying to do with it. There are some components that don't depends on Lua OPcodes and will run on LuaJIT and some components that do and as such are specific to Lua and won't run on LuaJIT (as it has different OPcodes).

Those components that are generic can still be useful though. For example, the Lua IDE I'm working on is using Lua Inspect, which relies on metalua to provide AST parsing. I've extracted those modules I need and implemented a wrapper that loads those modules in the right order. All this functionality runs on LuaJIT (2.0.2) without any issues.

Note that metalua github repository has some branches that includes newer metalua code; for example, tilo branch includes v0.6 while the master branch seems to only include v0.5. The reason you may be interested in the newer version is that there was some refactoring done to simplify usage of Lua only parts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top