[MacRuby-devel] Accessing Obj-C InstVars from Ruby

Laurent Sansonetti lsansonetti at apple.com
Sat Apr 4 20:01:57 PDT 2009


Hi Mathias,

On Apr 4, 2009, at 7:49 PM, Mathias Sulser wrote:

> I started working on this. I have a failing test case and figured a  
> way to hook in the objc lookup inside the ivar_get function.
> However, I haven't figured out how I can call  
> object_getInstanceVariable with an ROBJECT.. any hints appreciated.

Very cool!

You can simply cast the object as an `id'. In MacRuby, all objects  
except immediates [1] are Objective-C objects and can be casted as `id'.

Laurent

[1]: fixnums, true, false, nil, Qundef (not exported) - in your case  
these should already be caught earlier in ivar_get/set.

> Regards, Mathias
>
> On 3 Apr 2009, at 19:29, Laurent Sansonetti wrote:
>
>>
>> On Apr 1, 2009, at 8:07 AM, Benjamin Stiglitz wrote:
>>
>>>>>> Is there a way to access instance variables defined in an  
>>>>>> Objective-C
>>>>>> class from a Ruby extension?
>>>>
>>>> It is currently not implemented, but it's technically possible. A  
>>>> good work-around is to define accessors (properties) as John  
>>>> mentioned.
>>>
>>> Maybe we need MacRuby::Runtime to bubble up the Obj-C runtime. Or  
>>> FFI.
>>
>> Might be a nice feature, but in this case I think we should simply  
>> expose the existing Objective-C ivars in variable.c, by adding  
>> another lookup path. If someone is willing to investigate that let  
>> me know. Should not be that hard.
>>
>> Laurent
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel



More information about the MacRuby-devel mailing list