I finally managed to compile this thing with emscripten.
To prevent it from crashing every time when lua coroutine yields I had to add this compile flag
-s EXPORTED_RUNTIME_METHODS='["exceptionCaught"]'
I suppose lua uses longjmp which is technically an "exception"