Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebAssembly target for the luac.cross #3572

Open
Alfrederson opened this issue Apr 7, 2023 · 2 comments
Open

WebAssembly target for the luac.cross #3572

Alfrederson opened this issue Apr 7, 2023 · 2 comments

Comments

@Alfrederson
Copy link

Not really a missing feature, but something which would be really cool

In 2023, there could be an option to generate a browser-compatible version of the luac.cross tool. Lua is really easy to compile from source into wasm, e.g:

https://alfrederson.github.io/lua-web/

Justification

We can already upload a compiled firmware to the ESP32/8266 using the WebSerial API.
The Lua vm can easily be compiled to WebAssembly by replacing gcc with emcc in the Makefile within the /lua/luac_cross directory and commenting out two lines in luac.c, i.e:

CC := $(WRAPCC) emcc
...
# and also this line

IMAGE := ../../../luac.cross.html

And

// maybe add a || to also do this typedef when compiling with EMCC
// #if defined(_MSC_VER) || defined(__MINGW32__)
typedef unsigned int uint;
// #endif

I don't remember what else needs to be changed but it required very little effort (installing some dependencies and 1 or 2 compiler flags) to actually get luac.cross running within a html with the default emscripten shell. Just compiling it without changing anything else in the source file is enough to get the usage message on the browser's console. If the luac.c file is tweaked, it can be made to run lua code, e.g:

The implication of this is that there can be an online tool to generate everything else the luac.cross compiler generates, but without a dedicated server/containerized service. Since it's static, it could even be served from the ESP itself.

Question

One major problem I stumbled upon is that I couldn't get the luac.cross from the esp32 branch to compile without building the entire thing. Is the binary generated by the esp8266 branch of the luac.cross compatible with the ESP32 lua vm?

@HHHartmann
Copy link
Member

Sounds interesting. We would probably also need different versions for int and 64 Bit builds.
A PR would certainly be welcome.

@Alfrederson
Copy link
Author

Sounds interesting. We would probably also need different versions for int and 64 Bit builds. A PR would certainly be welcome.

It didn't work at all. I could get it to run but it produce non-viable bytecode. It was also impossible to make it generate the LFS image. It was easier to just dockerize the thing and create a simple API in go, e.g:

https://github.com/Alfrederson/luac.web

No need to run it on raspberry pi servers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants