[RubyCocoa] C pointers, and documentation

C

Christophe Mckeon

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
 
B

Brian Marick

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top