fengari-lua / fengari-node-cli

The Lua command line application, but using fengari under node.js
MIT License
29 stars 6 forks source link

Is the bytecode produced by fengaric supposed to be compatible with lua? #9

Closed shaoner closed 4 years ago

shaoner commented 4 years ago

Hello,

I've tried to re-use the bytecode produced by fengaric in lua and it doesn't seem to work, so I'm wondering if it's supposed to, or if my lua version is incompatible or if there's a way to do it?

I made sure to use lua 5.3 (tested with 5.3.0 and 5.3.5) but the bytecode seems to differ

$ cat test.lua
print('hello')
$ fengaric -o test.o test.lua
$ ./lua-5.3/lua -v
Lua 5.3.0  Copyright (C) 1994-2015 Lua.org, PUC-Rio
$ ./lua-5.3/lua test.o
lua: test.o: size_t size mismatch in precompiled chunk

vs

$ ./lua-5.3/luac -o test.o test.lua
$ ./lua-5.3/lua test.o
hello
$ fengaric -o test.o test.lua
$ fengari test.o
hello

To give more context, i'd like to send the bytecode version from nodejs (as a buffer) to program running in C that embeds the lua compiler.

daurnimator commented 4 years ago

This is expected: lua bytecode is specific to the ABI of machine you compiled it on and the flags you used to compile lua. For a "standard" x86_64 computer, you can often make fengari-compatible bytecode by compiling lua with -DLUA_INT_TYPE=LUA_INT_LONG. See https://github.com/fengari-lua/fengari#integers