3 ms·
The interaction between C and Javascript offered by Emscripten is a lot better than JNI on Android. I wish the Android NDK would steal a few ideas from Emscript
by flohofwoe 6y ago
The interaction between C and Javascript offered by Emscripten is a lot better than JNI on Android. I wish the Android NDK would steal a few ideas from Emscripten, but all the Android teams at Google don't seem to be able to look outside the nice comfy bubble they've created for themselves.
With Emscripten, you can embed Javascript source code directly into the C code and then call the embedded JS function from the C side as well as C functions from inside Javascript.
E.g. JS embedded in C code:
https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738bb7e740c964dc6bd56/sokol_audio.h#L1556-L1609 https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738b...
...called from C:
https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738bb7e740c964dc6bd56/sokol_audio.h#L1644 https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738b...
...and a C function:
https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738bb7e740c964dc6bd56/sokol_audio.h#L1530-L1549 https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738b...
...called from a JS function embedded in the C code:
https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738bb7e740c964dc6bd56/sokol_audio.h#L1580 https://github.com/floooh/sokol/blob/4c56a2ee15d81cac91b738b...
- iainmerrick 6y agoNot bad! Sounds like the tooling has improved since I last looked. How about debugging? Is it possible to step through a mix of C and JS stack frames?
- flohofwoe 6y agoThe Chrome devtools have added experimental DWARF debugging support, but for big projects that's still a bit of a hassle: https://developers.google.com/web/updates/2020/12/webassembly https://developers.google.com/web/updates/2020/12/webassembl... The embedded Javascript can be debugged as usual. In my case I usually debug the platform-agnostic code compiled natively in IDEs like Visual Studio or Xcode, and for the HTML5 specific code (which is just a few hundred lines) traditional "printf-debugging".