Are you sure it's so simple?

Calling this from C++ does not work properly:

TestStruct* testPtr = reinterpret_cast<TestStruct*>( emscripten_run_script_int("new Module.TestStruct(2.2);") );

while I can create TestStructs with the same constructor fine from within JavaScript (and emscripten_run_script_int works if I am actually returning an int)

note:

struct TestStruct {
    double a;
    TestStruct(double x) : a(x) {}
};

EMSCRIPTEN_BINDINGS(my_module) {
emscripten::class_<TestStruct>("TestStruct")
        .constructor<float>()
        .property("a", &TestStruct::a);
}


Thanks,
Josh

On 12/09/2015 06:54 PM, Brion Vibber wrote:

Simply return the pointer from the function with the 'return' statement, like any other function return value. Remember that pointers are just integers.

-- brion

On Dec 9, 2015 6:13 AM, "Josh A" <[email protected] <mailto:[email protected]>> wrote:

    Hi all,

    This seems like it should be really straight forward, but I can't
    find an example of this.

    I am trying to expose some scripting on my software:

    With embind I expose an Interface that should be implemented by
    javascript.  This works fine.

    Now I want to call some code that takes a provided js
    implementation of the interface, instatiates it and returns a
    pointer to C++ of the created object.  I can do the js call fine
    and everything works, but I can't seem to find how to get the
    pointer from the js back to the C++, either using an
    emscripten_run_script variant or using embind vars or some other
    method.

    I have tried searching, reading through docs and looking at the
    test code, but still can't find an example of this.  Can someone
    please point me to the right place?

    Thanks++
    Josh
-- 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]
    <mailto:[email protected]>.
    For more options, visit https://groups.google.com/d/optout.

--
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] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.


--
Dr. Joshua E. Auerbach
Postdoctoral Researcher
Laboratory of Intelligent Systems
École Polytechnique Fédérale de Lausanne

--
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