Moved module initialization code for defining Ruby module(s) out into

a separate function.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4242 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Logan Johnson 2003-01-28 15:03:47 +00:00
commit 21718b73da

View file

@ -204,6 +204,33 @@ public:
allow_overloading(); allow_overloading();
} }
/**
* Generate initialization code to define the Ruby module(s),
* accounting for nested modules as necessary.
*/
void defineRubyModule() {
List *modules = Split(module,':',INT_MAX);
if (modules != 0 && Len(modules) > 0) {
String *mv = 0;
String *m = Firstitem(modules);
while (m != 0) {
if (Len(m) > 0) {
if (mv != 0) {
Printv(f_init, tab4, modvar,
" = rb_define_module_under(", modvar, ", \"", m, "\");\n", NIL);
} else {
Printv(f_init, tab4, modvar,
" = rb_define_module(\"", m, "\");\n", NIL);
mv = NewString(modvar);
}
}
m = Nextitem(modules);
}
Delete(mv);
Delete(modules);
}
}
/* --------------------------------------------------------------------- /* ---------------------------------------------------------------------
* top() * top()
* --------------------------------------------------------------------- */ * --------------------------------------------------------------------- */
@ -310,27 +337,7 @@ public:
Printv(f_init, tab4, "SWIG_InitRuntime();\n", NIL); Printv(f_init, tab4, "SWIG_InitRuntime();\n", NIL);
/* Account for nested modules */ defineRubyModule();
List *modules = Split(module,':',INT_MAX);
if (modules != 0 && Len(modules) > 0) {
String *mv = 0;
String *m = Firstitem(modules);
while (m != 0) {
if (Len(m) > 0) {
if (mv != 0) {
Printv(f_init, tab4, modvar,
" = rb_define_module_under(", modvar, ", \"", m, "\");\n", NIL);
} else {
Printv(f_init, tab4, modvar,
" = rb_define_module(\"", m, "\");\n", NIL);
mv = NewString(modvar);
}
}
m = Nextitem(modules);
}
Delete(mv);
Delete(modules);
}
Printv(f_init, Printv(f_init,
"\n", "\n",