Is it possible to use "out" parameters with MacRuby, such as NSError? In my particular case I'd like to capture errors that result from parsing XML with NSXMLDocument using the initWithData:options:error: method. I tried (naively) just instantiating an NSError instance and handing it to that method, but ended up with this: irb(main):037:0> e = NSError.new => #<NSError:0x80067cc40> irb(main):038:0> doc = NSXMLDocument.alloc.initWithData(data, options:NSXMLDocumentValidate, error:e) ArgumentError: can't convert Ruby object `#<NSError:0x80067cc40>' to Objective-C value of type `^@' from (irb):38:in `initWithData:options:error:' from (irb):38 from /usr/local/bin/macirb:12:in `<main>' Any help or insight is appreciated. Cheers, Alex ---- Musings & Notes — http://alexvollmer.com Track what you lend and borrow — http://moochbot.com
errorp = Pointer.new_with_type("@") result = NSXMLDocument.alloc.initWithData(data, options:NSXMLDocumentValidate, error:errorp) # access error errorp[0] On 26 Apr 2009, at 16:36, Alex Vollmer wrote:
Is it possible to use "out" parameters with MacRuby, such as NSError? In my particular case I'd like to capture errors that result from parsing XML with NSXMLDocument using the initWithData:options:error: method. I tried (naively) just instantiating an NSError instance and handing it to that method, but ended up with this:
irb(main):037:0> e = NSError.new => #<NSError:0x80067cc40> irb(main):038:0> doc = NSXMLDocument.alloc.initWithData(data, options:NSXMLDocumentValidate, error:e) ArgumentError: can't convert Ruby object `#<NSError:0x80067cc40>' to Objective-C value of type `^@' from (irb):38:in `initWithData:options:error:' from (irb):38 from /usr/local/bin/macirb:12:in `<main>'
Any help or insight is appreciated.
Cheers,
Alex ---- Musings & Notes — http://alexvollmer.com Track what you lend and borrow — http://moochbot.com
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On Apr 26, 2009, at Apr 26, 10:09 AM, rebotfc wrote:
errorp = Pointer.new_with_type("@")
result = NSXMLDocument.alloc.initWithData(data, options:NSXMLDocumentValidate, error:errorp)
# access error errorp[0]
Ah cool. Thanks for the response. Is there any documentation on the possible values you can hand to the "new_with_type" method? What does that '@' sign mean? Thanks, ---- Musings & Notes — http://alexvollmer.com Track what you lend and borrow — http://moochbot.com
Hi Alex, On Apr 26, 2009, at 6:20 PM, Alex Vollmer wrote:
On Apr 26, 2009, at Apr 26, 10:09 AM, rebotfc wrote:
errorp = Pointer.new_with_type("@")
result = NSXMLDocument.alloc.initWithData(data, options:NSXMLDocumentValidate, error:errorp)
# access error errorp[0]
Ah cool. Thanks for the response. Is there any documentation on the possible values you can hand to the "new_with_type" method? What does that '@' sign mean?
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/A... In the case of a C structure, you can call the #type class method on the struct class. $ macirb irb(main):001:0> framework 'Foundation' => true irb(main):003:0> NSRect.type => "{CGRect={CGPoint=dd}{CGSize=dd}}" The next version of MacRuby will have a better Pointer class which will accept symbols like :int, :object, etc., but in the meantime you need to pass the Objective-C types. HTH, Laurent
On Apr 26, 2009, at Apr 26, 7:14 PM, Laurent Sansonetti wrote:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/A...
In the case of a C structure, you can call the #type class method on the struct class.
$ macirb irb(main):001:0> framework 'Foundation' => true irb(main):003:0> NSRect.type => "{CGRect={CGPoint=dd}{CGSize=dd}}"
The next version of MacRuby will have a better Pointer class which will accept symbols like :int, :object, etc., but in the meantime you need to pass the Objective-C types.
HTH, Laurent
Thanks! That clarifies a bunch. --Alex ---- Musings & Notes — http://alexvollmer.com Track what you lend and borrow — http://moochbot.com
On Apr 26, 2009, at 12:09 PM, rebotfc wrote:
errorp = Pointer.new_with_type("@")
result = NSXMLDocument.alloc.initWithData(data, options:NSXMLDocumentValidate, error:errorp)
# access error errorp[0]
So the RubyCocoa style of having by-reference arguments returned as extra return values is not included in MacRuby? ----- Brian Marick, independent consultant Mostly on agile methods with a testing slant www.exampler.com, www.exampler.com/blog, www.twitter.com/marick
On Apr 27, 2009, at 2:23 PM, Brian Marick wrote:
On Apr 26, 2009, at 12:09 PM, rebotfc wrote:
errorp = Pointer.new_with_type("@")
result = NSXMLDocument.alloc.initWithData(data, options:NSXMLDocumentValidate, error:errorp)
# access error errorp[0]
So the RubyCocoa style of having by-reference arguments returned as extra return values is not included in MacRuby?
Not yet. Laurent
participants (4)
-
Alex Vollmer
-
Brian Marick
-
Laurent Sansonetti
-
rebotfc