From: Knud H. M. <knu...@de...> - 2008-04-14 12:56:31
|
Hi Ferhat, thanks, I resolved the problem with the invalid initializer the way you described (a protocol works fine). However, I think my usecase involved another problem: Ruby only knows objects, no simpe datatypes (if I'm not mistaken). So, anything that is returned from Ruby to Obj-C is always an object. Thus, if I have a ruby method: def testNumber 666 end ... and call that from Obj-C, I need to explicitly convert the return value to an integer (if I want that): int aNumber = [[rubyObject testNumber] intValue]; That works. Now, what do I do with structs? E.g.: def dimensions OSX::NSSize.new(1024, 1024) # or: OSX::NSMakeSize(1024, 1024) end And from Obj-C: NSSize dimensions = [rubyObject dimensions]; This compiles (if I use the protocol method: http://www.rubycocoa.com/an-introduction-to-rubycocoa/4) , but results in nonsense data. Is there a way to do this correctly, or should I refrain from using structs alltogether? Cheers, Knud Am 14.04.2008 um 13:32 schrieb Ferhat Ayaz: > Ruby methods indeed do not define return types but Obj-C does. I'm > not sure but I guess the problem is that you are sending an > "unknown" message to dataSource and it treads it as obj-c id type. > So you would see the same compiler error if you try. > > id something; > NSSize originalSize = something; > > You have to define it in an obj-c interface. > > @interface KNTiledMap (ImNotSureButMaybeYouHaveToDoItAsCategory) > - (NSSize)dimensions; > @end > > > Ferhat > > ----- Original Message ---- > From: Knud Hinnerk Möller <knu...@de...> > To: rub...@li... > Sent: Monday, April 14, 2008 1:51:59 PM > Subject: Re: [Rubycocoa-talk] Importing Ruby Classes into Obj-C code > > > Am 14.04.2008 um 12:20 schrieb Ferhat Ayaz: > > > are you sure that [dataSource dimensions]; returns an NSSize? > > No, I can't be - Ruby methods don't define a return type. The error > already happens at compile time, not at runtime. > > Knud > > > > > > > Ferhat > > > > ----- Original Message ---- > > From: Knud Hinnerk Möller <knu...@de...> > > To: rub...@li... > > Sent: Monday, April 14, 2008 12:56:52 PM > > Subject: [Rubycocoa-talk] Importing Ruby Classes into Obj-C code > > > > Hi, > > > > please forgive me if this is a stupid question to ask, but is it > > possible to import a Ruby class definition into Obj-C? What I mean > is > > this: > > > > I have a RubyCocoa class: > > > > class KNTiledMap < OSX::NSObject > > attr_accessor :dimensions > > ... > > end > > > > I have an Obj-C class in which I want to use the Ruby class: > > > > @interface KNTileView : NSView { > > KNTiledMap *dataSource; > > } > > > > @implementation KNTileView > > ... > > NSSize originalSize = [dataSource dimensions]; > > ... > > @end > > > > This leads to a compile "error: invalid initializer". > > > > How can I make this work? > > > > Cheers, > > Knud > > ------------------------------------------------- > > Knud Möller, MA > > +353 - 91 - 495086 > > Smile Group: http://smile.deri.ie > > Digital Enterprise Research Institute > > National University of Ireland, Galway > > Institiúid Taighde na Fiontraíochta Digití > > Ollscoil na hÉireann, Gaillimh > > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > > Don't miss this year's exciting event. There's still time to save > > $100. > > Use priority code J8TL2D2. > > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > > _______________________________________________ > > Rubycocoa-talk mailing list > > Rub...@li... > > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk > > > > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > > Don't miss this year's exciting event. There's still time to save > > $100. > > Use priority code J8TL2D2. > > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone_______________________________________________ > > Rubycocoa-talk mailing list > > Rub...@li... > > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk > > ------------------------------------------------- > Knud Möller, MA > +353 - 91 - 495086 > Smile Group: http://smile.deri.ie > Digital Enterprise Research Institute > National University of Ireland, Galway > Institiúid Taighde na Fiontraíochta Digití > Ollscoil na hÉireann, Gaillimh > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save > $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save > $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone_______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk ------------------------------------------------- Knud Möller, MA +353 - 91 - 495086 Smile Group: http://smile.deri.ie Digital Enterprise Research Institute National University of Ireland, Galway Institiúid Taighde na Fiontraíochta Digití Ollscoil na hÉireann, Gaillimh |