How to call A.wasm 's exported function from B.wasm ?

39 views
Skip to first unread message

Yixin Chen

unread,
Nov 19, 2021, 8:02:48 PM11/19/21
to emscripten-discuss
I know there is EM_JS methood to call A.wasm in the browser. 

My question is, is there any direct way to import A.wasm in B.wasm, just like c++'s lib ?

Shlomi Fish

unread,
Nov 20, 2021, 12:58:40 AM11/20/21
to Yixin Chen, emscripte...@googlegroups.com
Hi!
Two ways I can think of:

1st way: using a JS bridge:
===========================

```
window.bmethodwrapper = (x) => {return B.wasm.bmethod(x,...);};
A.wasm.call('Amethod', window.bmethodwrapper);
```

2nd way: compiling both libraries into the same AandB.wasm:
===========================================================

as an amalgamated source.

--

Shlomi Fish https://www.shlomifish.org/
List of Networking Clients - https://shlom.in/net-clients

I before E, except after C. We live in a weird society.
— Source unknown, via Nadav Har’El.

Please reply to list if it's a mailing list post - https://shlom.in/reply .

Sam Clegg

unread,
Nov 21, 2021, 1:33:15 PM11/21/21
to emscripte...@googlegroups.com, Yixin Chen
You might also consider using emscripten's MAIN_MODULE/SIDE_MODULE dynamic linking mechanism: https://github.com/emscripten-core/emscripten/wiki/Linking

--
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-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/20211120075834.4df0655d%40shlomifish.org.
Reply all
Reply to author
Forward
0 new messages