diff --git a/Lib/javascript/jsc/javascriptcode.swg b/Lib/javascript/jsc/javascriptcode.swg index 000733ea7..0ad1e364d 100644 --- a/Lib/javascript/jsc/javascriptcode.swg +++ b/Lib/javascript/jsc/javascriptcode.swg @@ -244,6 +244,10 @@ int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObjec } %} +%fragment ("js_initializer_define", "templates") %{ +#define SWIGJSC_INIT $jsname_initialize +%} + /* ----------------------------------------------------------------------------- * js_initializer: template for the module initializer function * - $jsname: module name @@ -256,7 +260,7 @@ int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObjec extern "C" { #endif -bool $jsname_initialize(JSGlobalContextRef context) { +bool SWIGJSC_INIT (JSGlobalContextRef context) { SWIG_InitializeModule(0); JSObjectRef global_object = JSContextGetGlobalObject(context); diff --git a/Source/Modules/javascript.cxx b/Source/Modules/javascript.cxx index 90300a24f..f0b8c472a 100644 --- a/Source/Modules/javascript.cxx +++ b/Source/Modules/javascript.cxx @@ -1407,6 +1407,9 @@ int JSCEmitter::dump(Node *n) { // write the swig banner Swig_banner(f_wrap_cpp); + Template initializer_define(getTemplate("js_initializer_define")); + initializer_define.replace(T_NAME, module).pretty_print(f_header); + SwigType_emit_type_table(f_runtime, f_wrappers); Printv(f_wrap_cpp, f_runtime, "\n", 0); @@ -1414,7 +1417,7 @@ int JSCEmitter::dump(Node *n) { Printv(f_wrap_cpp, f_wrappers, "\n", 0); emitNamespaces(); - + // compose the initializer function using a template Template initializer(getTemplate("js_initializer")); initializer.replace(T_NAME, module)