From: Hugh Sasse Staff Elec Eng Date: 2002-01-16T20:12:52+09:00 Subject: Re: Swig Ruby documentation mods. On Wed, 16 Jan 2002, Luigi Ballabio wrote: > At 07:00 PM 1/16/02 +0900, Hugh Sasse Staff Elec Eng wrote: > > > Have you thought about sending to the swig project? > > > >Of course. No feedback so far from swig-dev on this. > > Well, Dave's feedback is here, I think: > http://mailman.cs.uchicago.edu/pipermail/swig-dev/2002-January/016502.html This was since then. I have joined the list, then started on the mods. http://mailman.cs.uchicago.edu/pipermail/swig-dev/2002-January/016586.html > However, it might be that he sent the mail to the list and not to you > personally, so that you might have missed it. > > As for you questions: > > >* if you don't use -module in the swig -ruby command then swig > > complains. This is probably always correct, but needs mentioning. > > Are you sure you are including the %module directive in your .i file? > I'm not using -module and SWIG doesn't complain. I'm not using a .i file -- I'm using the fact that swig -ruby example.c will generally work, as described elsewhere in the docs. > > >* It is not clear what should be done about integrating several C > > functions into the same module. Does this depend on one writing a .i > > file to connect them together? How? > > What I usually do is: > - somefuncs.i contains the declarations for some functions OK, > - someotherfuncs.i contains the declarations for some other functions > - I write a file mymodule.i containing: > > %module MyModule > %include somefuncs.i > %include someotherfuncs.i > > - by running SWIG on the latter file, all functions from the two original > ones will be exported in MyModule. Will it produce one "%s_wrap.c" or two? > > >* Can you make swig roll the C functions into methods of a class, or > > must one do this via including a module. > > If the functions all refer to a struct, you can do it in the usual SWIG way > (documented for other languages, so you can probably save yourself some > work by referring to the relevant places): [...] > After creating the extension you'll be able to use the struct as: > > s = MyModule::SomeStruct.new > s.f() > i = f.g() > x = f.h(2) OK, it always will come out as a module. I was thinking it could look like one had required a file just containing a class definition. > > If the functions are unrelated, You can declare an empty struct and do the > same thing, but you'll end up with instance methods, not static methods. If > the latter is what you want, you might be better off doing it on the Ruby > side. Finally, if you are not forced to use C only and can use C++, you can > create a class whose methods proxy the C functions and wrap such class with > SWIG. I think I'll leave that can of worms for another day, but thank you. > > >* Can extconf.rb be made to make other preliminary stuff, that is not > > part of the external interface of the class? Eg, can one make it run > > swig if necessary? > > The roughest way would be to make a system call before creating the > makefile, i.e., write extconf.rb as: > > require 'mkmf' > system('swig -ruby MyModule.i') > create_makefile('MyModule') That would build it, but it would build it always -- I wanted to get target: dependencies action stuff in there. I'll take that as a No for now. > > If you want to get fancy, you can compare the modification times of > MyModule.i and mymodule_wrap.cpp and run swig only when needed, as in: > > require 'mkmf' > require 'ftools' > system('swig -ruby MyModule.i') unless File.exists? "mymodule_wrap.cpp" and > File.mtime("mymodule_wrap.cpp") > File.mtime("MyModule.i") > create_makefile('MyModule') > > I didn't actually run the above code, so it might need corrections. > However, you get the drift. Yes, that sort of thing would work, but since extconf is supposed to be used to write a makefile, it seems a bit much to re-implement make inside it! :-) > > Hope this helped, > Luigi > >