I have ported 7kaa onto emscripten. There's some thinks that makes me frustrating, but I solve some of it.
- Emscripten main loop should call application loop in try ... catch(GoToLoop) block
- Emscripten_set_main_loop should save C stack into special JS array (each stack will be next element, so this array will be stack itself), save callback pointer and data(argument) onto other C array, change main loop to given and throw GoToLoop
- Add emscripten_cancel_loop, which pop old callback and data and set is as application loop, restore stack from highest element in JS array and return
- Add emscripten_yield, which save stack, change variable indicated it was called to 1, set timemout to function restoring stack and throw GoToLoop(),
- When emscripten_yield is called, but variable indicating it was called is 1, then emscripten only changes this variable value 0
This will allow to:
- Use multiple layers of application loop
- Do code like
And rest_of_code wi,l be called in the same context, when loop call emscripten_cancel_loop,
What do you think about that? I don't know it is possible to realize.