You can prepend or append additional JavaScript code to the generated module by specifying a file via the --pre-js or --post-js options on emcc (or by just taking the output JS and manually appending to it). This should make it fairly straightforward to set up initialization, such as by setting module options in a --pre-js, or creating a wrapper function that does the async setup for you.
Another thing that may help: if asynchronous setup of the module doesn't fit well with your code model, you can disable the memory file with "--memory-init-file 0" so all the code loading and initializers run immediately. This will however increase the total size of your code, as the data segments will be included as an array in the JS instead of a separate data file. -- brion vibber (brion @ pobox.com / bvibber @ wikimedia.org) On Fri, May 22, 2015 at 3:01 AM, Alexandre Perrot < [email protected]> wrote: > Hello, > > I have made my own js library using emscripten and I don't really know how > to manage initializatoin to be user-friendly. > > I use -s MODULARIZE=1 and EXPORT_NAME=My_lib, so the generated code only > gives a function named My_lib. > So, the user has to call the function himself and store the result : > var my_lib = My_lib(); > > I use embind, so after this function has exited, the library is not yet > ready since global initializers need to be run to init bindings. > > My question is how can I make sure everything is ready after calling an > init function ? > The objective is to have a user friendly way of initalizing the library, > such as : > > var my_lib = My_lib(); > my_lib.init() > do_something(); > > Wheras for now, I have to rely on 'postRun' to do that, which requires > users to know about emscripten : > > var my_lib = My_lib({'postRun' : do_something}); > > -- > 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.
