ziglua icon indicating copy to clipboard operation
ziglua copied to clipboard

Proof of concept: Emscripten build for Luau and Lua 5.x

Open luchak opened this issue 1 year ago • 2 comments

This is more of a FYI / potential resource for others than it is a real PR: the code is messy, has a few chunks lifted from sokol-zig, and a couple of the examples have been switched to c_allocator to dodge Emscripten's allergy to the page allocator . If you just close the PR I won't take offense. :)

Anyway, I'm trying to integrate Luau into a project based on sokol-zig, and while that's not all wired up yet, I do have the interpreter example running in the browser (using Emscripten's atrocious stdin UX). The main issue appeared to be getting both compilation and linking for C++ code to refer to the same versions of the C++ libs, STL, etc. The only way I could really get this to work was to take sokol-zig's linker step (and a bunch of the surrounding emsdk setup code), and add another helper to do compilation as well.

Also had to make sure that the example never invokes the page allocator, directly or otherwise, since that's an instant crash with Emscripten.

To the extent that any bits are interesting, those are probably buildLuauEmscripten and emCompileStep.

I've gone ahead and gotten Lua 5.x to build w/ Emscripten as well. Unsure why it was necessary to include a stub stdio.h ... but no stub for any other system header was required.

luchak avatar Sep 16 '24 06:09 luchak

I did try to build Lua 5.x without using emcc to compile - just using it for the linking step - but that triggers the longjmp issues.

luchak avatar Sep 18 '24 03:09 luchak

Thank you for looking into this! I am not super familiar with Emscripten but this does seem worthwhile. I don't have time right now to take a closer look, but feel free to keep working on this and ping me if you ever get things working!

natecraddock avatar Sep 20 '24 18:09 natecraddock

Related to PR #86

nii236 avatar May 20 '25 03:05 nii236