diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index e19b781c2..48da0cf48 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -1,4 +1,5 @@ %insert(runtime) %{ +#include #include #include #include @@ -20,6 +21,45 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) { static bool already_init=false; if (already_init) return octave_value_list(); + + // parse command line + const char* usage="usage: " SWIG_name_d " [-global|-noglobal] [-globals ]"; + bool global_load=SWIG_global_load; + std::string global_name=SWIG_global_name; + for (int j=0;jassign(swig_globals[j].name,&swig_globals[j]); octave_swig_type* module_ns=new octave_swig_type(0, 0, 0, true); - module_ns->assign("cvar",Swig::swig_value_ref(cvar_ns)); + module_ns->assign(global_name,Swig::swig_value_ref(cvar_ns)); for (int j=0;swig_globals[j].name;++j) if (swig_globals[j].method) module_ns->assign(swig_globals[j].name,&swig_globals[j]); @@ -68,7 +101,7 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) { // the incref is necessary so install_global doesn't destroy module_ns, // as it would if it installed something with the same name as the module. module_ns->incref(); - if (global_option) + if (global_load) module_ns->install_global(); module_ns->decref(); diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index ab53340fe..dcd690844 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -15,9 +15,14 @@ char cvsroot_octave_cxx[] = "$Id$"; #include "swigmod.h" +static bool global_load = true; +static String *global_name = 0; + static const char *usage = (char *) "\ Octave Options (available with -octave)\n\ - [no additional options]\n\ + -global - Load all symbols into the global namespace [default]\n\ + -globals - Set used to access C global variables [default: 'cvar']\n\ + -noglobal - Do not load all symbols into the global namespace\n\ \n"; @@ -64,11 +69,29 @@ public: for (int i = 1; i < argc; i++) { if (argv[i]) { if (strcmp(argv[i], "-help") == 0) { - fputs(usage, stdout); - } + fputs(usage, stderr); + } else if (strcmp(argv[i], "-global") == 0) { + global_load = true; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-noglobal") == 0) { + global_load = false; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-globals") == 0) { + if (argv[i + 1]) { + global_name = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } } } + if (!global_name) + global_name = NewString("cvar"); + SWIG_library_directory("octave"); Preprocessor_define("SWIGOCTAVE 1", 0); SWIG_config_file("octave.swg"); @@ -131,6 +154,10 @@ public: Printf(f_runtime, "#define SWIG_name_d \"%s\"\n", module); Printf(f_runtime, "#define SWIG_name %s\n", module); + Printf(f_runtime, "\n"); + Printf(f_runtime, "#define SWIG_global_load %s\n", global_load ? "true" : "false"); + Printf(f_runtime, "#define SWIG_global_name \"%s\"\n", global_name); + if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); Swig_banner(f_directors_h);