diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index 8a01e7c76..3229299d5 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -112,6 +112,7 @@ Options specific to the Octave module are: Octave Options (available with -octave) -global - Load all symbols into the global namespace [default] -globals name - Set name used to access C global variables [default: 'cvar'] + - Use '.' to load C global variables into module namespace -noglobal - Do not load all symbols into the global namespace -opprefix str - Prefix str for global operator functions [default: 'op_'] @@ -119,6 +120,7 @@ Octave Options (available with -octave)

The -global and -noglobal options determine whether the Octave module will load all symbols into the global namespace in addition to the global namespace. The -globals option sets the name of the variable which is the namespace for C global variables exported by the module. +The special name "." loads C global variables into the module namespace, i.e. alongside C functions and structs exported by the module. The -opprefix options sets the prefix of the names of global/friend operator functions.

diff --git a/Examples/octave/module_load/runme_args.m b/Examples/octave/module_load/runme_args.m index 271cdd289..716ee31f9 100644 --- a/Examples/octave/module_load/runme_args.m +++ b/Examples/octave/module_load/runme_args.m @@ -38,3 +38,11 @@ example -globals mycvar assert(!isglobal("cvar")) assert(mycvar.ivar == example.ifunc()) ##### END TEST ##### + +clear all; + +##### BEGIN TEST ##### +# load module with root-level cvar +example -globals . +assert(example.ivar == example.ifunc()) +##### END TEST ##### diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index bb173eb22..1fde2e796 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -33,7 +33,7 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) { if (!already_load) { // parse command line - const char* usage="usage: " SWIG_name_d " [-global|-noglobal] [-globals ]"; + 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* cvar_ns=0; + if (global_name != ".") { + cvar_ns=new octave_swig_type; + for (int j=0;swig_globals[j].name;++j) + if (swig_globals[j].get_method) + cvar_ns->assign(swig_globals[j].name,&swig_globals[j]); + } octave_swig_type* module_ns=new octave_swig_type(0, 0, 0, true); - module_ns->assign(global_name,Swig::swig_value_ref(cvar_ns)); + if (global_name != ".") { + module_ns->assign(global_name,Swig::swig_value_ref(cvar_ns)); + } + else { + for (int j=0;swig_globals[j].name;++j) + if (swig_globals[j].get_method) + module_ns->assign(swig_globals[j].name,&swig_globals[j]); + } for (int j=0;swig_globals[j].name;++j) if (swig_globals[j].method) module_ns->assign(swig_globals[j].name,&swig_globals[j]); diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 7bf33169b..0186ca412 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -23,6 +23,7 @@ static const char *usage = (char *) "\ Octave Options (available with -octave)\n\ -global - Load all symbols into the global namespace [default]\n\ -globals - Set used to access C global variables [default: 'cvar']\n\ + - Use '.' to load C global variables into module namespace\n\ -noglobal - Do not load all symbols into the global namespace\n\ -opprefix - Prefix for global operator functions [default: 'op_']\n\ \n";