I am using emscripten to provide Javascript bindings for some libraries. Emsripten packages the code into a namespace (global var), called 'Module'.
I want to change the naming so that I can use a name that reflects what the library is used for, and also to prevent variable name collisions further down the line, as I write bindings for other libraries.
I can't find anywhere in the documentation, that shows how to do this. Does anyone know how I can change the default namespace used by emscripten?
I am using emscripten to provide Javascript bindings for some libraries. Emsripten packages the code into a namespace (global var), called 'Module'.
I want to change the naming so that I can use a name that reflects what the library is used for, and also to prevent variable name collisions further down the line, as I write bindings for other libraries.
I can't find anywhere in the documentation, that shows how to do this. Does anyone know how I can change the default namespace used by emscripten?
Share Improve this question asked May 10, 2015 at 14:34 Homunculus ReticulliHomunculus Reticulli 68.5k86 gold badges227 silver badges362 bronze badges 01 Answer
Reset to default 16You can change the EXPORT_NAME
setting from the default of Module
. You can do this on the mand line as an options to emcc
:
emcc -s EXPORT_NAME="'MyEmscriptenModule'" <other options...>
and then the module will be available on the global scope by whatever name you specified:
window.MyEmscriptenModule == {...}
Note that if you set the MODULARIZE
setting to be 1, then whatever is set as EXPORT_NAME
will be created as a function in the global scope that you must call to initialise the module. You can pass a settings object to this function, and it will return the module instance back:
var myModuleInstance = window.MyEmscriptenModule({noInitialRun: true});
If you're using some a module loader, such as RequireJS, and don't want to add anything to the global namespace at all, an alternative is to use the --pre-js <file>
and --post-js <file>
options to wrap the final Javascript, as in this answer to a question on Emscripten with module loaders.