Import an external javascript library in LibraryManager.library

109 views
Skip to first unread message

vitopigno

unread,
Apr 9, 2023, 2:31:53 PM4/9/23
to emscripten-discuss
I want to import an external JavaScript library (in this case Pixi.js, the module version if
possible) when compiling with emscripten, making it avaible to use inside JavaScript functions, for example:
#include <emscripten.h> int main() { EM_ASM( // Start PIXI.js let app = new PIXI.Application({//...}); ); return 0; }I have some experience with c++ and emscripten but I never tried to make c++ work with JavaScript so this code could be probably wrong. But I couldn't find anything about this other than some mentions on some GitHub posts. Did someone ever tried to do this? If yes could making a Pixi program inside c++ or at least importing a larger library without declare every function be feasible?

vitopigno

unread,
Apr 9, 2023, 4:48:07 PM4/9/23
to emscripten-discuss
Just an update, I found a quick and dirty way to achieve this:

<script type="module">
        import * as PIXI from './pixi.mjs';
        window.PIXI = PIXI;
</script>


The pixi library can now be accessed from c++ by using 'emscripten::val pixi = val::global("PIXI")'
This isn't a good solution since it makes PIXI global including it inside the window object. I think there are better ways to do this, but I couldn't find any on the official emscripten documentation.
Reply all
Reply to author
Forward
0 new messages