You can do it with something like this

uint32_t objID = ++globalID;
val someJSObject;
val::global("MyObjectTracker")[objID] = someJSObject;
EM_ASM_INT({ 
  var objToUse = MyObjectTracker[$0];
}, objID);



On Friday, July 1, 2016 at 4:44:51 AM UTC-7, Reuben Scratton wrote:
>
> Thanks for the reply juj, any chance you could point me to an example of 
> how to do this? Am afraid I just can't work it out.
>
> I am also wanting to pass JS objects as parameters to Runtime.dynCall() 
> and store them in vals on the C++ side... presumably once I understand 
> manual marshalling this will be easy.
>
>
> On Tuesday, June 21, 2016 at 12:59:51 PM UTC+1, jj wrote:
>>
>> I think we don't currently have anything built-in for that, but you 
>> should marshall the object manually, e.g. by managing a table or other 
>> location where the object exists, and referencing that object via an int.
>>
>> 2016-06-20 19:06 GMT+03:00 Reuben Scratton <reuben....@gmail.com>:
>>
>>> Hi,
>>>
>>> I'd like to pass a reference to a javascript object into an EM_ASM_ 
>>> block, i.e :
>>>
>>> {
>>>     val jsObj = ... whatever ...;
>>>
>>>     EM_ASM_ ({
>>>         var obj = $0;
>>>         ...
>>>     }, jsObj);
>>>
>>> }
>>>
>>> But the compiler won't let me do this... it seems only trivial values 
>>> (ints and doubles and strings) are allowed to go in and out of the js block.
>>>
>>> What are my options here? The js object in question can actually be 
>>> created inside the block but I do need to hold a long-lived reference to it 
>>> from the C++ world. It'd be helpful if there was an EM_ASM_OBJ macro so I 
>>> could simply return it to the C++ side...
>>>
>>> Many thanks,
>>>
>>>
>>> Reuben
>>>
>>> -- 
>>> 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 emscripten-discuss+unsubscr...@googlegroups.com.
>>> 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 emscripten-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to