Hi i'm porting a C++ API with a class member function

class System
{
    ...
    setUserData(void *userdata);
    getUserData(void **userdata);

    void *mUserData;   // typically in C the value is stored here
}

and in javascript i'd like to be able to pass any type of object so that I 
can store it in the class (either in my void * pointer or any other type of 
pointer).  
ie

    var test = "hello";
    var test_out = {};
    gSystem.setUserData(test);               // test = "hello"
    gSystem.getUserData(test_out);        // test_out.val = "hello"

but also var test could be a number, or struct, or any other type of object.

Above, the getUserData is setting a member of the JS object called "val" , 
via set("val", value);  We use this pattern with other standard types of 
functions (that take strings/numbers/etc) and it works well.
The issue i'm having is trying to bind my setUserData function to take a 
/generic/ object so I can store it, then just set it as the "val" for the 
getUserData function.

I've 
found 
https://github.com/kripken/emscripten/blob/master/tests/embind/embind_test.cpp 
useful for trying all different types of binding, but I don't want to 
create a new object in the C++ side to store the object.   I had a working 
version that created an emscripten::val of type object() on the C++ side, 
and stored it, and returned that object in the getUserData side, but I dont 
want to create any intermediate objects , I just want to store whatever 
comes in and pass the same thing back.

I've tried all sorts of things including messing with allow_raw_pointers, 
creating a val_holder (which creates a temporary store) and treating the 
parameter as if it was a smart pointer or void * (it gives an error param 
type pV not supported), but i'm just stabbing in the dark at the moment.

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