How can I call C++ callback asynchronously from JavaScript?


This is my JS code:


<script type="text/javascript">
  function sendRequest(callback) {   
    setTimeout(function(){
      callback["sayHi"]();
    }, 100);
  }
</script>


This is my C++ code:


#include <emscripten/emscripten.h>
#include <emscripten/bind.h>

using namespace emscripten;   
class MyClass {
  public:
    void sayHi () {
      printf("Hello! \n");
    };
};
EMSCRIPTEN_BINDINGS(MyClass)
{
  class_<MyClass>("MyClass")
    .function("sayHi", &MyClass::sayHi);
}

int main() {
  val window = val::global("window");
  auto myObj = MyClass();
  window.call<void>("sendRequest", myObj);
  return 0;
}


When I execute this code in browser it fails with error:

Uncaught BindingError: Cannot pass deleted object as a pointer of type 
MyClass*


I use emcc 1.35.22 and compile it with this command:

~/app/emsdk_portable/emscripten/tag-1.35.22/emcc main.cpp --bind -o out.js


Thank you in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to