Tim Burks
tim****@neont*****
Fri Jan 5 08:31:33 JST 2007
Hi Jean Pierre, On Jan 4, 2007, at 3:13 PM, jeanp****@gmail***** wrote: > hi hi - > > continuing on from my earlier investigations posted to the > rubycocoa-talk list, i installed rubycocoa 0.9 from source and gave > it a whirl. i've run into a few oddities that i thought i'd ask about. > > [1] for some reason, i can't seem to compile objC code into a > bundle and require it in ruby *unless* i name the bundle > client.bundle. i have attached a little sample project, if you run > rake it'll build 'client.bundle ' from the provided source and if > you run helper.rb it'll just print out a quick debug line after > requiring the built bundle. strangely enough, if i name the bundle > something other than 'client.bundle' and require it in helper.rb, > it gives me a load error on the require: > > LoadError: Failed to lookup Init function ./schoolkid.bundle > > exactly the same code, just using a different bundle name... > You need an Init_* function in your ObjC code. Change "Init_Client" to "Init_YourNewBundleName". > [2] is rubycocoa doing some sort of memory management on allocated > objC objects? i thought with 0.5 that if i allocated and > initialized an objC derived object that i'd also need to release > it, but with 0.9, doing so causes a segfault. > > kid = OSX::SchoolKid.alloc.init > kid.release > Don't do that. That will overrelease kid. RubyCocoa won't detect that the retain that you just sent caused the underlying object to be deleted. > > [3] should i be able to override objC methods in ruby? if i have > some objC class: > @interface SchoolKid : NSObject { > } > - (NSString *)saySomething; > @end > > @implementation SchoolKid > - (NSString *)saySomething { > return @"sorry, I am quiet"; > } > @end > > and try to reopen the class in ruby to override a method, nothing > happens: > class OSX::SchoolKid > def saySomething > puts "hi" > end > end > > but i can subclass and override: > class OtherKid < OSX::SchoolKid > def saySomething > puts "halllo" > end > end > > ns_overrides seems to have disappeared, is there a proper way to do > this? (i'm trying to mock objC objects in ruby). > I've found the same problem, it's related to the trick that is being used to automatically import the class. When it automatically imports a class in a class declaration, the wrong class is used when the body of the class is parsed. For example, add this "puts" to your code and rerun it (or use OSX.NSLog). > class OSX::SchoolKid puts self.superclass > def saySomething > puts "hi" > end > end You'll probably see that it's "Object" instead of OSX::NSObject. > > [4] is OSX.ns_import no longer required? > generally, but you can use it to work around the above problem. Just OSX.ns_import :SchoolKid before you open the class for modification. Tim > > thats all for now =) > thanks for any help that can be provided! > cheers, > jean-pierre > > > <helper.rb> > <Rakefile> > <SchoolKid.h> > <SchoolKid.m> > _______________________________________________ > Rubycocoa-devel mailing list > Rubyc****@lists***** > http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel