Pointers for BOOL types
The following method takes a ptr->BOOL. I've played around but cannot figure out how to create a pointer to a true/false that then returns true/false via its accessor. - (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory The following doesn't work: framework 'Cocoa' p1 = Pointer.new_with_type('@') p1.assign(false) p1[0] == false # => false, but should be true Then I figured I should be able to pass BOOL to -new_with_type as it is the data type, but BOOL isn't recognised. Perhaps test_objc.rb could include some more examples/coverage of Pointer usage too? -- Dr Nic Williams iPhone and Rails consultants - http://mocra.com Fun with iPhone/Ruby/Rails/Javascript - http://drnicwilliams.com * Surf Report for iPhone - http://mocra.com/projects/surfreport/ *
The following doesn't work:
framework 'Cocoa' p1 = Pointer.new_with_type('@') p1.assign(false) p1[0] == false # => false, but should be true
Then I figured I should be able to pass BOOL to -new_with_type as it is the data type, but BOOL isn't recognised.
The type for bool is upper case B. If you replace @ with B in your example it works fine. Just a little warning about pointers: they tend to forget their type if you read the value returned by a function twice. Do not try to read more than once their value (just store the value returned by #[] in a Ruby variable). However, reusing the same pointer in multiple calls seems to work fine. For example the following code: # rects was retuned by NSLayoutManager#rectArrayForCharacterRange puts rects[0] puts rects[0] Displays: #<NSRect origin=#<NSPoint x=5.0 y=0.0> size=#<NSSize width=0.0 height=19.0>> xxxxx.rb:222:in `[]': unrecognized octype `?_?' (RuntimeError)
Ah, thanks. I've looked thought the src now, and it seems _C_ID and _C_BOOL might correspond to "@" and "B" but I can't find where they are defined; not in macruby src nor in Cocoa Dev Documentation. Where is the list of available Pointer types + their character code? Cheers Nic On Fri, Jan 2, 2009 at 10:15 AM, Vincent Isambart <vincent.isambart@gmail.com> wrote:
The following doesn't work:
framework 'Cocoa' p1 = Pointer.new_with_type('@') p1.assign(false) p1[0] == false # => false, but should be true
Then I figured I should be able to pass BOOL to -new_with_type as it is the data type, but BOOL isn't recognised.
The type for bool is upper case B. If you replace @ with B in your example it works fine.
Just a little warning about pointers: they tend to forget their type if you read the value returned by a function twice. Do not try to read more than once their value (just store the value returned by #[] in a Ruby variable). However, reusing the same pointer in multiple calls seems to work fine. For example the following code: # rects was retuned by NSLayoutManager#rectArrayForCharacterRange puts rects[0] puts rects[0]
Displays: #<NSRect origin=#<NSPoint x=5.0 y=0.0> size=#<NSSize width=0.0 height=19.0>> xxxxx.rb:222:in `[]': unrecognized octype `?_?' (RuntimeError) _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
-- Dr Nic Williams iPhone and Rails consultants - http://mocra.com Fun with iPhone/Ruby/Rails/Javascript - http://drnicwilliams.com * Surf Report for iPhone - http://mocra.com/projects/surfreport/ *
Hey Nic Cheque it: http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/A... :lachie http://smartbomb.com.au http://www.flickr.com/photos/lachie/ On Fri, Jan 2, 2009 at 1:04 PM, Dr Nic Williams <drnicwilliams@gmail.com> wrote:
Ah, thanks.
I've looked thought the src now, and it seems _C_ID and _C_BOOL might correspond to "@" and "B" but I can't find where they are defined; not in macruby src nor in Cocoa Dev Documentation.
Where is the list of available Pointer types + their character code?
Cheers Nic
On Fri, Jan 2, 2009 at 10:15 AM, Vincent Isambart <vincent.isambart@gmail.com> wrote:
The following doesn't work:
framework 'Cocoa' p1 = Pointer.new_with_type('@') p1.assign(false) p1[0] == false # => false, but should be true
Then I figured I should be able to pass BOOL to -new_with_type as it is the data type, but BOOL isn't recognised.
The type for bool is upper case B. If you replace @ with B in your example it works fine.
Just a little warning about pointers: they tend to forget their type if you read the value returned by a function twice. Do not try to read more than once their value (just store the value returned by #[] in a Ruby variable). However, reusing the same pointer in multiple calls seems to work fine. For example the following code: # rects was retuned by NSLayoutManager#rectArrayForCharacterRange puts rects[0] puts rects[0]
Displays: #<NSRect origin=#<NSPoint x=5.0 y=0.0> size=#<NSSize width=0.0 height=19.0>> xxxxx.rb:222:in `[]': unrecognized octype `?_?' (RuntimeError) _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
-- Dr Nic Williams iPhone and Rails consultants - http://mocra.com Fun with iPhone/Ruby/Rails/Javascript - http://drnicwilliams.com * Surf Report for iPhone - http://mocra.com/projects/surfreport/ * _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Sweet, thanks. On Fri, Jan 2, 2009 at 12:37 PM, Lachie <lachiec@gmail.com> wrote:
Hey Nic
Cheque it: http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/A...
:lachie http://smartbomb.com.au http://www.flickr.com/photos/lachie/
On Fri, Jan 2, 2009 at 1:04 PM, Dr Nic Williams <drnicwilliams@gmail.com> wrote:
Ah, thanks.
I've looked thought the src now, and it seems _C_ID and _C_BOOL might correspond to "@" and "B" but I can't find where they are defined; not in macruby src nor in Cocoa Dev Documentation.
Where is the list of available Pointer types + their character code?
Cheers Nic
On Fri, Jan 2, 2009 at 10:15 AM, Vincent Isambart <vincent.isambart@gmail.com> wrote:
The following doesn't work:
framework 'Cocoa' p1 = Pointer.new_with_type('@') p1.assign(false) p1[0] == false # => false, but should be true
Then I figured I should be able to pass BOOL to -new_with_type as it is the data type, but BOOL isn't recognised.
The type for bool is upper case B. If you replace @ with B in your example it works fine.
Just a little warning about pointers: they tend to forget their type if you read the value returned by a function twice. Do not try to read more than once their value (just store the value returned by #[] in a Ruby variable). However, reusing the same pointer in multiple calls seems to work fine. For example the following code: # rects was retuned by NSLayoutManager#rectArrayForCharacterRange puts rects[0] puts rects[0]
Displays: #<NSRect origin=#<NSPoint x=5.0 y=0.0> size=#<NSSize width=0.0 height=19.0>> xxxxx.rb:222:in `[]': unrecognized octype `?_?' (RuntimeError) _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
-- Dr Nic Williams iPhone and Rails consultants - http://mocra.com Fun with iPhone/Ruby/Rails/Javascript - http://drnicwilliams.com * Surf Report for iPhone - http://mocra.com/projects/surfreport/ * _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
-- Dr Nic Williams iPhone and Rails consultants - http://mocra.com Fun with iPhone/Ruby/Rails/Javascript - http://drnicwilliams.com * Surf Report for iPhone - http://mocra.com/projects/surfreport/ *
On Thu, Jan 1, 2009 at 7:37 PM, Lachie <lachiec@gmail.com> wrote:
Cheque it: http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/A...
see also: /usr/include/objc/runtime.h Dave
So kind of on this topic .. which one of these ("c", "i", "s" etc) do I use for void pointers (to memory) eg. the data parameter in the method below? (when otherwise appropriately changed to ruby and Application.services imported etc). CGContextRef CGBitmapContextCreate ( void *data, size_t width, size_t height, size_t bitsPerComponent, size_t bytesPerRow, CGColorSpaceRef colorspace, CGBitmapInfo bitmapInfo ); Cheers, J On Jan 2, 2009, at 11:21 PM, Dave Lee wrote:
On Thu, Jan 1, 2009 at 7:37 PM, Lachie <lachiec@gmail.com> wrote:
Cheque it: http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/A... /apple_ref/doc/uid/TP40008048-CH100-SW1
see also: /usr/include/objc/runtime.h
Dave _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
try "^v". ^ is pointer, v is void. If you look at the .bridgesupport file, in this case /System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/BridgeSupport/CoreGraphicsFull.bridgesupport, you'll see the the objc types listed for the various functions, structs, etc. Dave On Sat, Jan 3, 2009 at 12:28 AM, John Shea <johnmacshea@gmail.com> wrote:
So kind of on this topic .. which one of these ("c", "i", "s" etc) do I use for void pointers (to memory) eg. the data parameter in the method below? (when otherwise appropriately changed to ruby and Application.services imported etc).
CGContextRef CGBitmapContextCreate ( void *data, size_t width, size_t height, size_t bitsPerComponent, size_t bytesPerRow, CGColorSpaceRef colorspace, CGBitmapInfo bitmapInfo );
Cheers,
J
On Jan 2, 2009, at 11:21 PM, Dave Lee wrote:
On Thu, Jan 1, 2009 at 7:37 PM, Lachie <lachiec@gmail.com> wrote:
Cheque it: http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/A...
see also: /usr/include/objc/runtime.h
Dave _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Thanks for the pointer ( ;-)) Dave, I assume that there is some way to make it work since it seems, as you say, to be catered for, but with my code it either gives back garbage (ie not a pointer to the image i want) or falls into the debugger depending on whether i access it more than once. Never mind, I have a work-around that works fine - it was easy to call out to an Objective C method where I could create the pointer in the C way (void *data = malloc(width * height * 4);). Cheers, John On Thu, Jan 8, 2009 at 6:45 PM, Dave Lee <davelee.com@gmail.com> wrote:
try "^v". ^ is pointer, v is void.
If you look at the .bridgesupport file, in this case
/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/BridgeSupport/CoreGraphicsFull.bridgesupport, you'll see the the objc types listed for the various functions, structs, etc.
Dave
On Sat, Jan 3, 2009 at 12:28 AM, John Shea <johnmacshea@gmail.com> wrote:
So kind of on this topic .. which one of these ("c", "i", "s" etc) do I use for void pointers (to memory) eg. the data parameter in the method below? (when otherwise appropriately changed to ruby and Application.services imported etc).
CGContextRef CGBitmapContextCreate ( void *data, size_t width, size_t height, size_t bitsPerComponent, size_t bytesPerRow, CGColorSpaceRef colorspace, CGBitmapInfo bitmapInfo );
Cheers,
J
On Jan 2, 2009, at 11:21 PM, Dave Lee wrote:
On Thu, Jan 1, 2009 at 7:37 PM, Lachie <lachiec@gmail.com> wrote:
Cheque it:
http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/A...
see also: /usr/include/objc/runtime.h
Dave _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
If it helps, for CGBitmapContextCreate you just pass NULL ('nil' in MacRuby) for the void *data parameter and let CoreGraphics handle allocating memory. Unless you really need to do the allocation yourself, it is significantly less painful and less error-prone to have it done automatically, especially if you're using CoreGraphics from MacRuby. Brian On Fri, Jan 9, 2009 at 12:00 AM, John Shea <johnmacshea@gmail.com> wrote:
Thanks for the pointer ( ;-)) Dave, I assume that there is some way to make it work since it seems, as you say, to be catered for, but with my code it either gives back garbage (ie not a pointer to the image i want) or falls into the debugger depending on whether i access it more than once. Never mind, I have a work-around that works fine - it was easy to call out to an Objective C method where I could create the pointer in the C way (void *data = malloc(width * height * 4);). Cheers, John
On Thu, Jan 8, 2009 at 6:45 PM, Dave Lee <davelee.com@gmail.com> wrote:
try "^v". ^ is pointer, v is void.
If you look at the .bridgesupport file, in this case
/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/BridgeSupport/CoreGraphicsFull.bridgesupport, you'll see the the objc types listed for the various functions, structs, etc.
Dave
On Sat, Jan 3, 2009 at 12:28 AM, John Shea <johnmacshea@gmail.com> wrote:
So kind of on this topic .. which one of these ("c", "i", "s" etc) do I use for void pointers (to memory) eg. the data parameter in the method below? (when otherwise appropriately changed to ruby and Application.services imported etc).
CGContextRef CGBitmapContextCreate ( void *data, size_t width, size_t height, size_t bitsPerComponent, size_t bytesPerRow, CGColorSpaceRef colorspace, CGBitmapInfo bitmapInfo );
Cheers,
J
On Jan 2, 2009, at 11:21 PM, Dave Lee wrote:
On Thu, Jan 1, 2009 at 7:37 PM, Lachie <lachiec@gmail.com> wrote:
Cheque it:
http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/A...
see also: /usr/include/objc/runtime.h
Dave _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Hi Brian, thanks for your comment. Strangely enough that's what I did by accident the first time. It actually seems a bit dodgy (at least to my way of thinking) - that not only are the objects of my method parameter list changing, but that the repository of my data if nil will dictate a different behaviour in the method. I am not a no-side-effect bigot guy, but I can think of clearer ways to structure methods. So it then took me a while to figure out why my program was not working because i kept thinking - "but my data is just waiting to be filled - I set it to nil!" - and in fact post method, the "data" reference was still pointing to nil. (There were a lot of more obvious things that could be wrong, that i went through first - and having cycled through three different Apple graphics technologies already ...) I actually need this data pointer to pop into an opengl call. Trying to reference it by : data = CGBitmapContextGetData(context) does not work. and: data = Pointer.new_with_type('^v') #data = CGBitmapContextGetData(context) data.assign(CGBitmapContextGetData(context)) does not work either (although at least it does not crash - so the type seems to be correct - the pointer is just not pointing to the correct bitmap and garbage is sent to the opengl method). data = CGBitmapContextGetData(context) will work for me if i create the context (and malloc the data ref) in objective c and return the context. Thats my workaround and it works fine. Cheers, John. On Jan 9, 2009, at 11:57 PM, Brian Chapados wrote:
If it helps, for CGBitmapContextCreate you just pass NULL ('nil' in MacRuby) for the void *data parameter and let CoreGraphics handle allocating memory. Unless you really need to do the allocation yourself, it is significantly less painful and less error-prone to have it done automatically, especially if you're using CoreGraphics from MacRuby.
Brian
On Fri, Jan 9, 2009 at 12:00 AM, John Shea <johnmacshea@gmail.com> wrote:
Thanks for the pointer ( ;-)) Dave, I assume that there is some way to make it work since it seems, as you say, to be catered for, but with my code it either gives back garbage (ie not a pointer to the image i want) or falls into the debugger depending on whether i access it more than once. Never mind, I have a work-around that works fine - it was easy to call out to an Objective C method where I could create the pointer in the C way (void *data = malloc(width * height * 4);). Cheers, John
On Thu, Jan 8, 2009 at 6:45 PM, Dave Lee <davelee.com@gmail.com> wrote:
try "^v". ^ is pointer, v is void.
If you look at the .bridgesupport file, in this case
/System/Library/Frameworks/ApplicationServices.framework/ Frameworks/CoreGraphics.framework/Resources/BridgeSupport/ CoreGraphicsFull.bridgesupport, you'll see the the objc types listed for the various functions, structs, etc.
Dave
On Sat, Jan 3, 2009 at 12:28 AM, John Shea <johnmacshea@gmail.com> wrote:
So kind of on this topic .. which one of these ("c", "i", "s" etc) do I use for void pointers (to memory) eg. the data parameter in the method below? (when otherwise appropriately changed to ruby and Application.services imported etc).
CGContextRef CGBitmapContextCreate ( void *data, size_t width, size_t height, size_t bitsPerComponent, size_t bytesPerRow, CGColorSpaceRef colorspace, CGBitmapInfo bitmapInfo );
Cheers,
J
On Jan 2, 2009, at 11:21 PM, Dave Lee wrote:
On Thu, Jan 1, 2009 at 7:37 PM, Lachie <lachiec@gmail.com> wrote:
Cheque it:
http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/A... /apple_ref/doc/uid/TP40008048-CH100-SW1
see also: /usr/include/objc/runtime.h
Dave _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
participants (6)
-
Brian Chapados
-
Dave Lee
-
Dr Nic Williams
-
John Shea
-
Lachie
-
Vincent Isambart