[MacRuby-devel] Quartz 2D Graphics problem
Steve Clarke
steve at sclarkes.me.uk
Mon Oct 22 04:28:13 PDT 2012
Hi,
While you can't mix and match within one file, I think you can have a Class that contains both Objective C methods and Macruby methods each defined in their own file. Objective C classes are open and the Macruby methods will be added to them.
Steve
On 21 Oct 2012, at 20:28, Colin Thomas-Arnold <colinta at gmail.com> wrote:
> yup, you can't mix and match within one file.
>
>
> @colinta
> colinta.com
> github.com/colinta
>
>
>
>
> On Oct 21, 2012, at 1:22 PM, Robert Carl Rice wrote:
>
>> Hi,
>>
>> Actually, I already have PBSerialPort m & h files by Paolo Bosetti dropped into my project and it works fine. I was wondering is a class could have both Objective C and Ruby code but from this discussion I gather the class must be either MacRuby or ObjC. Is this correct?
>>
>> Thanks,
>> Bob Rice
>>
>>
>> On Oct 21, 2012, at 2:40 PM, Jim Getzen <jim at getzen.name> wrote:
>>
>>> You don't need to make a framework or bundle to add Obj-C code to your project. I've been able to just add a .h/.m files directly to the project and call the Obj-C classes contained therein from my MacRuby code, just as if those classes were part of a framework.
>>>
>>> What you can't do, of course, is call straight C functions or constants without a bridgesupport file.
>>>
>>> Jim
>>>
>>>
>>> On Oct 21, 2012, at 12:59 PM, Mark Rada <mrada at marketcircle.com> wrote:
>>>
>>> Adding some Objective-C code could be done with a framework as suggested, or by creating a bundle. The bundle process is essentially the same as creating a C extension for Ruby. Any MacRuby project with a C extension could be used as an example:
>>>
>>> https://github.com/pieter/macruby-bundle-example
>>> https://github.com/Marketcircle/AXElements/tree/master/ext/accessibility/key_coder
>>> https://github.com/alloy/ObjectiveBacon/tree/master/LanguageBindings/MacRuby/ext
>>>
>>> You can then simply "require 'bundle'" the bundle file that is compiled.
>>>
>>>
>>> On 2012-10-21, at 12:44 PM, Colin Thomas-Arnold <colinta at gmail.com> wrote:
>>>
>>>> You can certainly compile a group of stuff as a framework, and add that framework to your project, but I've never tried to just toss in .h/.m files and access them from macruby.
>>>>
>>>> Can anyone touch on that? I'm interested to hear what can be done there...
>>>>
>>>>
>>>> AFA translating your code into Obj-C...
>>>>
>>>>
>>>> Here's the short version:
>>>>
>>>> self.context = [[NSGraphics currentContext] graphicsPort];
>>>>
>>>>
>>>>
>>>> And here's the long version!
>>>>
>>>>
>>>> // the header file, YourClass.h
>>>>
>>>> @interface YourClass : ParentClass
>>>>
>>>> @property (assign, nonatomic) CGContextRef context;
>>>> // or void* instead of CGContextRef, but graphicsPort returns a CGContextRef
>>>>
>>>> @end
>>>>
>>>>
>>>>
>>>> // the implementation file, YourClass.m
>>>>
>>>> #import "YourClass.h"
>>>>
>>>> @implementation YourClass
>>>>
>>>> @synthesize context;
>>>>
>>>> - drawRect:(CGRect)rect
>>>> {
>>>> self.context = [[NSGraphics currentContext] graphicsPort];
>>>> }
>>>>
>>>> @end
>>>>
>>>>
>>>>
>>>>
>>>> @colinta
>>>> colinta.com
>>>> github.com/colinta
>>>>
>>>>
>>>>
>>>>
>>>> On Oct 21, 2012, at 10:19 AM, Robert Carl Rice wrote:
>>>>
>>>>> Hi Mark,
>>>>>
>>>>> Unfortunately, I am not very familiar with objective C syntax. Is it easy to mix objective C statements with MacRuby?
>>>>> For example, How would code the @context = NSGraphicsContext.currentContext.graphicsPort in objective C?
>>>>>
>>>>> Thanks,
>>>>> Bob Rice
>>>>
>>>> _______________________________________________
>>>> MacRuby-devel mailing list
>>>> MacRuby-devel at lists.macosforge.org
>>>> http://lists.macosforge.org/mailman/listinfo/macruby-devel
>>>
>>> _______________________________________________
>>> MacRuby-devel mailing list
>>> MacRuby-devel at lists.macosforge.org
>>> http://lists.macosforge.org/mailman/listinfo/macruby-devel
>>>
>>> _______________________________________________
>>> MacRuby-devel mailing list
>>> MacRuby-devel at lists.macosforge.org
>>> http://lists.macosforge.org/mailman/listinfo/macruby-devel
>>
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo/macruby-devel
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo/macruby-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20121022/6a99ebbd/attachment-0001.html>
More information about the MacRuby-devel
mailing list