Submodules and C

Hi,
Suppose I want to make a “Math::Const” submodule. What should I call the
Init_* function so that the require is something sensible. Is this even
possible?

Could the ‘require’ be something like:

require ‘math::const’

But you can’t make a C function called Init_math::const

What is the best way to deal with the issue of submodules and require’s?

···


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

Daniel Carrera wrote:

Hi,
Suppose I want to make a “Math::Const” submodule. What should I call the
Init_* function so that the require is something sensible. Is this even
possible?

Could the ‘require’ be something like:

require ‘math::const’

You mean include, right?

But you can’t make a C function called Init_math::const

What is the best way to deal with the issue of submodules and require’s?

Excerpt from README.ETC:

To define nested classes or modules, use the functions below:

VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
VALUE rb_define_module_under(VALUE outer, const char *name)

Joel VanderWerf wrote:

Excerpt from README.ETC:
oops… README.EXT

No, I really do mean require.
I know that the include would be:

include Math::Const

But what I’m asking about is if there is any standard for the “require”
line, when you are requiring a submodule. I think that it would be
confusing to have:

require ‘const’
include Math::Const

And I’m trying to figure out a ‘require’ line that can convey the idea of
a submodule. One idea is:

require ‘mathConst’
include Math::Const

So the C function would be called Init_mathConst().

Another idea is to let the C function be called Init_const, and make a
“math::const.rb” file that wraps around it, since “:” is a perfectly
good file-name character. Something like this:

============ math::const.rb =========
require ‘const’

···

On Sat, Jan 25, 2003 at 01:07:02PM +0900, Joel VanderWerf wrote:

require ‘math::const’

You mean include, right?

=======================================

Now you can do:

require ‘math::const’
include Math::Const

I am wondering what people usually make the “require” line when you are
requiring a submodule.


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

Daniel Carrera wrote:

require ‘math::const’

You mean include, right?

No, I really do mean require.
I know that the include would be:

include Math::Const

Ah, sorry. I understand the issue now. Your wrapper idea sounds
workable. Or maybe ‘require “math/const”’.

I’ve never tried it, but what if the Init_X() function and Y.so (or
Y.dll) have X != Y ?

In other words, does ruby’s loader look for Init_FOO when opening
FOO.so, or will it run any Init_BAR that it finds? I’m guessing not,
from what README.EXT says, but this might solve the problem.

···

On Sat, Jan 25, 2003 at 01:07:02PM +0900, Joel VanderWerf wrote:

Ah, sorry. I understand the issue now. Your wrapper idea sounds
workable. Or maybe ‘require “math/const”’.

That’s probably the best idea. I think I’ll do that.

After I thought about it, perhaps ‘math::const.rb’ was probably a bad
idea. There might be a system somewhere that might have problems with the
“::” characters.

I’ve never tried it, but what if the Init_X() function and Y.so (or
Y.dll) have X != Y ?

In other words, does ruby’s loader look for Init_FOO when opening
FOO.so, or will it run any Init_BAR that it finds? I’m guessing not,
from what README.EXT says, but this might solve the problem.

ruby’s loader looks for Init_FOO in FOO.so and Init_BAR won’t work.

Cheers,

···

On Sat, Jan 25, 2003 at 01:37:52PM +0900, Joel VanderWerf wrote:


Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

Hi,

Ah, sorry. I understand the issue now. Your wrapper idea sounds
workable. Or maybe ‘require “math/const”’.

That’s probably the best idea. I think I’ll do that.

After I thought about it, perhaps ‘math::const.rb’ was probably a bad
idea. There might be a system somewhere that might have problems with the
“::” characters.

Under classical MacOS, “::” meant the parent directory.
Although ruby doesn’t work there.

I’ve never tried it, but what if the Init_X() function and Y.so (or
Y.dll) have X != Y ?

In other words, does ruby’s loader look for Init_FOO when opening
FOO.so, or will it run any Init_BAR that it finds? I’m guessing not,
from what README.EXT says, but this might solve the problem.

ruby’s loader looks for Init_FOO in FOO.so and Init_BAR won’t work.

Also note that it is case-sensitive.

···

At Sat, 25 Jan 2003 13:46:32 +0900, Daniel Carrera wrote:


Nobu Nakada