You can append to `DEFAULT_LIBRARY_FUNCS_TO_INCLUDE`, all those will be
included. And it is possible to do so in a js library, as {{{ }}} executes
code. Here is an example from library.js,

{{{ (DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('emscripten_replace_memory'),
'') }}}

(the output of executing the code is placed inline, so this make sure to
emit just '').

- Alon


On Sun, Oct 19, 2014 at 4:52 AM, Pepijn Van Eeckhoudt <
[email protected]> wrote:

> To keep the number of parts to my solution limited I would like to put
> everything in the js-library part if possible. I can make the lookup table
> accessible via a function in the js lib. It seems that if there’s no code
> that actually depends on a particular symbol that the linker discards it.
> Is there anything I can do to force a function to be retained? A JS
> equivalent of EMSCRIPTEN_KEEPALIVE if you will.
>
> Pepijn
>
> On 17 Oct 2014, at 22:54, Alon Zakai <[email protected]> wrote:
>
> You can just put things on the Module object yourself. Write the JS to do
> it, using Module['name'] = value (so it works in closure too), then add it
> as a --post-js to your C++ code, and then normal JS from outside will be
> able to access it.
>
> - Alon
>
>
> On Fri, Oct 17, 2014 at 7:14 AM, Pepijn Van Eeckhoudt <
> [email protected]> wrote:
>
>> Hi,
>>
>> I'm in the process of making a tool similar to webidl-binder. Right now
>> I'm trying to add support for callback interfaces, but I'm a bit stuck on
>> how to get this working.
>>
>> What I would like to do is be able to make an implementation of a
>> callback interface in Javascript, pass it to C++ and then invoke methods on
>> the callback object. I'm trying to implement this using a lookup table
>> where callback objects get registered and assigned an id when first passed
>> to C++. On the C++ side a proxy object is created which wraps the id value
>> and dispatches member functions to functions defined in Javascript. Those
>> functions are included using the --js-library flag as per the documentation.
>>
>> In the code below I've put the object lookup table inside the js-library.
>> The problem I have now is that I need some way to access that lookup table
>> (directly or indirectly) from Javascript code that isn't processed by
>> emscripten. I think the most reliable way to do this will be to export the
>> table via the Module object. My question is how I can do this. Is there any
>> way to force symbols defined in a js-library to be exported via Module? Or
>> is there an easier strategy to implement callbacks?
>>
>> Thanks,
>>
>> Pepijn
>>
>> Example code showing the pattern I'm trying to implement follows.
>>
>> In my test IDL file I have something like
>> interface Test {
>>   void callMeBack(Callback c);
>> };
>> callback interface Callback {
>>   void callback(Test t);
>> };
>>
>> The C++ implementations for Test and Callback are (abbreviated)
>> void Test::callMeBack(Callback *cb) {
>>   cb->callback(this);
>> }
>>
>> class Callback {
>>   int handle;
>>   Callback(int handle) : handle(handle) {}
>>   void callback(Test* test) {
>>     js_callback_Callback_callback(this->handle, test);
>>   }
>> };
>>
>> extern "C" {
>>   void emscripten_operation_Callback_callback(int handle, Test* test);
>> }
>>
>> And finally the JS library looks like this
>> mergeInto(LibraryManager.library,{
>>     $CALLBACK_OBJECTS: {
>>         cache: []
>>     },
>>     emscripten_operation_Callback_callback: function (handle, test_ptr) {
>>         CALLBACK_OBJECTS.cache[handle].callback(test_ptr);
>>     }
>> });
>>
>> --
>> 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.
>>
>
>
> --
> 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.
>
>
>

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