The approach taken by Benoit is the *only* good way forward to get lua
working in in web browsers to full effect:
Hmm, well, that seems a bit overbroad. There are lots of applications that use lua in a web browser to great effect via emscripten.
and both environments having references to eachothers objects, but who really needs that anyways? If they both talk primarily to the C / C++
then there's no issue, and it's actually very performant in recent versions of firefox and chrome, even though you have the "VM inside a VM" thing
Also FWIW emscripten supports longjmp, and to a lesser extent C++ exceptions, and lua coroutines seem to work great even in a large application
I worked on.
from there -- I can see that that might be very difficult to do in a satisfactory way.
But if you are doing a C or C++ project and want to target the web and use lua, there are no real obstacles, and in my experience it all works great.
I didn't have any memory leaks or round-robin garbage collector issues, and I think you will only have these problems if you structure your application that way.
The other thing is, rewriting the lua VM in hand is likely to have much worse performance than the cross-compiled version, unless you target ASM.js which
will allow the browser to JIT compile it into native code. ASM.js is not meant to be written by hand, and it's not easy to do so -- it's meant to be output by
their llvm-based backend. If you don't get the JIT stuff to happen in the browser, it's like a 5x or 10x performance hit. So tbh I'm a bit skeptical of the "rewrite the lua vm
in JS" approach, depending on what kinds of applications you have in mind.