From efd8f86d899d3e22b5f7b79ee8401d41d6db9d1a Mon Sep 17 00:00:00 2001 From: Logan Johnson Date: Fri, 25 Apr 2003 16:03:50 +0000 Subject: [PATCH] Added the -globalmodule command-line option for the Ruby module, which allows the user to wrap all classes, methods and constants directly into the global module (i.e. the Kernel module) instead of a named, nested module. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4706 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ Doc/Manual/Ruby.html | 23 ++++++++++++++++------- Source/Modules/ruby.cxx | 6 +++++- TODO | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 0e8d64f85..05c0db1ce 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,5 +1,10 @@ Version 1.3.20 (In progress) ============================ +04/25/2003: ljohnson (Lyle Johnson) + [Ruby] Added the -globalmodule command-line option for the Ruby + module, for wrapping stuff into the global module (Kernel) instead + of a nested module. Updated documentation accordingly. + 04/23/2003: mrose (Mark Rose) Fixed symname error in director calls to Python methods that extend C++ operators. diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index cbe7cd99a..834d7630d 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -211,8 +211,7 @@ Ruby module names must be capitalized, but the convention for Ruby feature names is to use lowercase names. So, for example, the Etc extension module is imported by requiring the etc feature: -
-# The feature name begins with a lowercase letter... +
# The feature name begins with a lowercase letter... require 'etc' # ... but the module name begins with an uppercase letter @@ -224,8 +223,7 @@ To stay consistent with this practice, you should always specify a SWIG will automatically correct the resulting Ruby module name for your extension. So for example, a SWIG interface file that begins with: -
-%module example +
%module example
will result in an extension module using the feature name "example" and @@ -364,9 +362,20 @@ nested directly under the global module. You can specify a more deeply nested module by specifying the fully-qualified module name in quotes, e.g.
%module "Foo::Bar::Spam"
-When choosing a module name, do not use the same -name as a built-in Ruby command or standard module name, the results may be -unpredictable. +Starting with SWIG 1.3.20, you can also choose to wrap everything into the global +module by specifying the -globalmodule option on the SWIG command line, i.e. + +
$ swig -ruby -globalmodule example.i
+ +Note that this does not relieve you of the requirement of specifying the SWIG +module name with the %module directive (or the -module +command-line option) as described earlier.

+ +When choosing a module name, do not use the same name as a built-in Ruby command +or standard module name, as the results may be unpredictable. Similarly, if you're +using the -globalmodule option to wrap everything into the global module, +take care that the names of your constants, classes and methods don't conflict +with any of Ruby's built-in names.

20.3.2 Functions

diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index adb2b20cf..d1a3c3308 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -92,6 +92,7 @@ static const char * usage = "\ Ruby Options (available with -ruby)\n\ -ldflags - Print runtime libraries to link with\n\ + -globalmodule - Wrap everything into the global module\n\ -feature name - Set feature name (used by `require')\n"; @@ -177,6 +178,9 @@ public: } else { Swig_arg_error(); } + } else if (strcmp(argv[i],"-globalmodule") == 0) { + useGlobalModule = true; + Swig_mark_arg(i); } else if (strcmp(argv[i],"-help") == 0) { Printf(stderr,"%s\n", usage); } else if (strcmp (argv[i],"-ldflags") == 0) { @@ -1330,7 +1334,7 @@ public: Printv(klass->init, klass->vname, " = rb_define_class_under(", modvar, ", \"", klass->name, "\", $super);\n", NIL); } else { - Printv(klass->init, klass->vname, " = rb_define_class_under(\"", + Printv(klass->init, klass->vname, " = rb_define_class(\"", klass->name, "\", $super);\n", NIL); } diff --git a/TODO b/TODO index 5904d735c..b683e089c 100644 --- a/TODO +++ b/TODO @@ -279,7 +279,7 @@ Ruby * Add some special directives to automatically rename declarations to or from CamelCase. -* Consider adding a switch to define everything in the global (Kernel) +[DONE] Consider adding a switch to define everything in the global (Kernel) module instead of nested in a user-defined module, but only if it comes up.