Re: LuaJIT and WebAssembly

  • From: Paul Kaletta <pk@xxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 17 Apr 2017 19:29:39 +0200

Am 17.04.2017 um 17:43 schrieb Coda Highland:

On Sat, Apr 15, 2017 at 9:43 AM, Paul Kaletta <pk@xxxxxxxxxxxxxxx> wrote:
Hi everybody,

I recently learned about WebAssembly/WASM, a bytecode format for web
browsers.

https://en.wikipedia.org/wiki/WebAssembly
http://webassembly.org/

The format is suitable as a compilation target for C/C++ compilers, and so
the original Lua already runs in a WASM environment.

https://github.com/vvanders/wasm_lua

Are there any plans add a WebAssembly target to LuaJIT?  I realize that
porting LuaJIT to a new target architecture is quite an undertaking, but I
wanted to inquire whether there is any hope.

Best regards,
Paul

I'm not sure I understand the impetus. WebAssembly is already
JIT-compiled, and you wouldn't have access to the FFI, so what benefit
would LuaJIT derive from such a port?

/s/ Adam


My guess is that WASM is not JIT-compiled, but "statically" compiled to native machine code. If I understand things correctly, WASM is more like (a portable variant) of LLVM bit-code and less like Java byte code. Full translation to target machine code can happen before execution, there is no tracing JIT compiler involved.

If LuaJIT's fast interpreter was ported to WASM, LuaJIT (the language) would become available in the browser. I don't know enough about LuaJIT's trace compiler to asses whether it can be made to emit WASM. This is why I inquired.

I also don't see why LuaJIT's FFI should not be available. If one can compile C to WASM, and LuaJIT's interpreter was available in a WASM version, it should be possible to call C code from LuaJIT programs via LuaJIT's FFI.

My impetus is this: I'm working on a program, written in C++, that uses imgui as a gui toolkit. Thanks to asm.js or WebAssembly and WebGL, programs that use this toolkit can run in the browser (e.g. http://floooh.github.io/oryol-samples/asmjs/ImGuiDemo.html, this demo uses asm.js and not WASM, but you get the idea).

I would love to use LuaJIT (the language) as a scripting language in my program, but so far LuaJIT (the implementation) will not run in the browser. If I want the same scripting language both in the browser, and in a "native" environment, I need to go with PUC Lua. I think that WebAssembly will only become more and more important, especially for game developers.

Best regards,
Paul


Other related posts: