[RubyCocoa] C pointers, and documentation

Discussion in 'Ruby' started by Christophe Mckeon, Dec 17, 2008.

  1. hi,

    how are C pointers handled on the rubycocoa side?
    for example a method like the following:

    - (BOOL)validateValue:(id *)ioValue
    forKey:(NSString *)key
    error:(NSError **)outError

    is there a standard way of handling it? is this
    kind of thing documented anywhere?

    thanks for any tips,
    _c
    --
    Posted via http://www.ruby-forum.com/.
    Christophe Mckeon, Dec 17, 2008
    #1
    1. Advertising

  2. Christophe Mckeon

    Brian Marick Guest

    On Dec 17, 2008, at 12:13 PM, Christophe Mckeon wrote:
    > error:(NSError **)outError
    >
    > is there a standard way of handling it? is this
    > kind of thing documented anywhere?


    There's a class called ObjcPtr that's used to translate to/from such
    arguments. Google around for that word and you'll find sketchy
    documentation. Here's an example of stuffing a value into such an
    "out" parameter:

    def getObjectValue_forString_errorDescription(objptr, s, errdesc)
    case s.to_ruby.downcase
    when 'yes': objptr.assign(true)
    when 'no': objptr.assign(false)
    else return false
    end
    true
    end

    To pull an object out of a pointer-to-object, you do this:

    def observeValueForKeyPath_ofObject_change_context(
    keyPath, object, change, rawContext)
    context = rawContext.cast_as('@')
    puts "Context: #{context.inspect}"
    end

    The '@' identifies the thing-being-pointed-to as an object. There are
    other symbols to identify things like raw machine integers, etc. I
    forget where you find them, but they're not RubyCocoa-specific, so
    they're somewhere in Apple documentation.

    For non-objects there are also methods like "int_at", "bool_at",
    "bool", and "int". I haven't had reason to use them yet, so I don't
    know the details.

    -----
    Brian Marick, independent consultant
    Mostly on agile methods with a testing slant
    www.exampler.com, www.exampler.com/blog, www.twitter.com/marick

    -----
    Brian Marick, independent consultant
    Mostly on agile methods with a testing slant
    www.exampler.com, www.exampler.com/blog, www.twitter.com/marick
    Brian Marick, Dec 18, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    667
  2. Phil Tomson
    Replies:
    8
    Views:
    99
    Ollivier Robert
    Mar 6, 2004
  3. Harry
    Replies:
    0
    Views:
    104
    Harry
    Jun 22, 2004
  4. anne001
    Replies:
    5
    Views:
    113
    anne001
    Nov 14, 2005
  5. John N. Alegre

    RubyCocoa and DarwinPorts Ruby?

    John N. Alegre, Feb 26, 2006, in forum: Ruby
    Replies:
    3
    Views:
    97
Loading...

Share This Page