[MacRuby-devel] MacRuby pointers and Obj-C function returning a value by reference

2013-01-21 Thread kwic...@wichry.net
I am trying to implement the following method of NSAttributedString in Macruby:

- (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index 
effectiveRange:(NSRangePointer)aRange

As by definition, it `Returns the value for an attribute with a given name of 
the character at a given index, and by reference the range over which the 
attribute applies.`

OK, so I need a pointer to NSRange, which I set up as follows:

range=Pointer.new("{_NSRange=QQ}")[0]

It seems to be fine as `range.class` => `NSRange`.

However, when I execute the method: 


font=txtStor.attribute(NSFontAttributeName,atIndex:index,effectiveRange:range)

my `range` is always `#`. Also, `p range` gives me 
`#`.

Any ideas how to implement this correctly?

Thanks
K
___
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo/macruby-devel


[MacRuby-devel] MacRuby pointers and Obj-C function returning a value by reference

2013-01-22 Thread kwic...@wichry.net
Thanks Watson

It was helpful and actually it is not even needed to assign the value to the 
range.

I realised that I was dereferencing the object in wrong places.

Best

K

> 
> Date: Tue, 22 Jan 2013 07:30:47 +0900
> From: Watson 
> To: "MacRuby development discussions."
>   
> Subject: Re: [MacRuby-devel] MacRuby pointers and Obj-C function
>   returning a alue by reference
> Message-ID: 
> Content-Type: text/plain; charset="utf-8"
> 
> Hi
> 
> Maybe, you could write your code as following:
> 
> $ macirb --simple-prompt
>>> framework 'AppKit'
> => true
>>> range = Pointer.new(NSRange.type)
> => #
>>> range.assign NSMakeRange(0,1)
> => #
>>> str = NSAttributedString.alloc.initWithString("hello")
> => hello{
> }
>>> str.attribute(NSUnderlineStyleAttributeName, atIndex:0, 
>>> effectiveRange:range)
> => nil
> 
> 
> 
> Cheers.
> Watson
> 
>> I am trying to implement the following method of NSAttributedString in 
>> Macruby:
>> 
>> - (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index 
>> effectiveRange:(NSRangePointer)aRange
>> 
>> As by definition, it `Returns the value for an attribute with a given name 
>> of the character at a given index, and by reference the range over which the 
>> attribute applies.`
>> 
>> OK, so I need a pointer to NSRange, which I set up as follows:
>> 
>> range=Pointer.new("{_NSRange=QQ}")[0]
>> 
>> It seems to be fine as `range.class` => `NSRange`.
>> 
>> However, when I execute the method: 
>> 
>> font=txtStor.attribute(NSFontAttributeName,atIndex:index,effectiveRange:range)
>> 
>> my `range` is always `#`. Also, `p range` gives 
>> me `#`.
>> 
>> Any ideas how to implement this correctly?
>> 
>> Thanks
>> K
>> ___
>> MacRuby-devel mailing list
>> MacRuby-devel@lists.macosforge.org 
>> (mailto:MacRuby-devel@lists.macosforge.org)
>> http://lists.macosforge.org/mailman/listinfo/macruby-devel
>> 
>> 
> 

___
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo/macruby-devel