Open Interrupt opened 3 weeks ago
Dug more into this, that unknown type name was due to the Zig library not having the correct headers - the Lua library did have the right ones but the Zig library was including some of Lua's C files directly and calling into them which makes sense.
The next issue I found though is harder to work around:
warning: undefined symbol: _longjmp (referenced by root reference (e.g. compiled C/C++ code))
warning: undefined symbol: _setjmp (referenced by root reference (e.g. compiled C/C++ code))
In POSIX mode it can't seem to find _longjmp / _setjmp
, in non-POSIX it complains about a similar missing longjmp / setjmp
.
It's possible to work around this by modifying ziglua's build.zig file to turn off Lua error handling, but that does not seem to be ideal.
Turning off the error handling can be done by adding the following to the Lua build flags:
-DLUAI_THROW(L,c)={return;}
-DLUAI_TRY(L,c,a)=a
-Dluai_jmpbuf=int
I pushed a 0.3.0 release to ziglua earlier today and then I was thinking about this issue. Thanks for digging into it a bit more!
Yeah I was thinking about how there are functions not available in wasm. We may need a new build option to enable/disable things :)
Thinking about this more, maybe what is needed is a way to modify the Lua build flags by the upstream builder pulling in the ziglua dependency. The sokol-zig project does something like this when linking against emscripten, there's an emLinkStep
function that among other things takes an array of extra argument flags to use in the form of extra_args: []const []const u8 = &.{},
Is this the only thing you needed to get it working with emscripten? https://github.com/Interrupt/ziglua/commit/3d7532ec73202bddfbeba1933d43fe427ca6d80d
Yes, but that is a super hacky solution! It turns off all of the debug printing amongst other stuff.
When making a web build for Emscripten, and linking ziglua with the Emscripten system headers, linking fails with an error like:
This might be because
-DLUA_USE_POSIX
is passed in build.zig for all unknown targets, and the WASM case isn't handled.