Passing a C++ function to a javascript function in emscripten

Viewed 3545

I am learning about emscripten and trying to understand it better. As far as I understand the use-case it was mostly designed for is to port existing C/C++-code to a web client (browser) and calling C/C++ code from JavaScript.

But I am wondering whether it is possible to use C++ and Emscripten to web page (note: this is more out of curiosity - I know that there are not many good reasons to do that at the moment). I manage to call Javascript functions from C++ and pass arguments of types string, int, double etc to them. But what I am missing is: calling a Javascript function from C++ and passing a C or C++ function as a handle. So as a simple example: How would I write the following Javascript code ind pure C++?

var myfun = function() { /* do something meaningful here */ }
document.onload(myfun);
3 Answers
Related