I'm climbing the learning curve with embind and  having difficulty using 
the documentation for Deriving from C++ classes in Javascript 
<https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#deriving-from-c-classes-in-javascript>
 to 
produce working code. The test embind_test.cpp 
<https://github.com/emscripten-core/emscripten/blob/master/tests/embind/embind_test.cpp>
 
looks like it should be sufficient to fill in the gap in my understanding, 
but isn't quite doing it.

My main sticking point right now is that it seems that I am missing some 
critical bit of information for how to update Module to include the 
prototype for the interface I am trying to extend.

The abstract base class is declared with this:

struct JsPredictInterface
{
explicit JsPredictInterface(const std::string& modelUri);

virtual ~JsPredictInterface();
virtual tz::Tenzor predict(const tz::Tenzor& input) = 0;

std::string mModelUri;
};

(The method predict and in particular its use of tz::Tenzor must still be 
implemented, and is shown only to illustrate my intent. I have confirmed 
that if I comment out all code related to the predict interface that the 
problem below still occurs.)

The bindings for it are declared with this:

struct JsPredictWrapper : public emscripten::wrapper<JsPredictInterface>
{
EMSCRIPTEN_WRAPPER(JsPredictWrapper);

tz::Tenzor predict(const tz::Tenzor& input)
{
return call<tz::Tenzor>("predict", input);
}
};

EMSCRIPTEN_BINDINGS(JsPredictInterface) {
emscripten::class_<JsPredictInterface>("JsPredictInterface")
.function("predict", &JsPredictInterface::predict, emscripten::pure_virtual
())
.allow_subclass<JsPredictWrapper>("JsPredictWrapper", emscripten::
constructor<std::string>())
;
}

I attempt to extend the interface with this code:

EM_JS(void, createImpl, (emscripten::val context, std::string modelPath), {
const assert = require('assert');
assert.ok(Module);
assert.ok(Module.JsPredictInterface);
const PredictorImpl = 
Module.JsPredictInterface.extend("JsPredictInterface", {
...
});

const impl = new PredictorImpl(modelPath);

context = {...context, impl};
});

When the function createImpl is called it  fails with the assertion 
assert.ok(Module.JsPredictInterface).

What am I likely missing to ensure that Module includes the 
JsPredictInterface object? Do I have to write the code to update Module? So 
far my reading of the documentation has led me to believe that this would 
be taking care of by the EMSCRIPTEN_BINDINGS implementation.

Thanks.


-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/e9b539a5-89f6-4a60-a38b-abf47265b30an%40googlegroups.com.

Reply via email to