最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Changing the default namespace 'Module' in emscripten - Stack Overflow

programmeradmin4浏览0评论

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 0
Add a ment  | 

1 Answer 1

Reset to default 16

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

发布评论

评论列表(0)

  1. 暂无评论