Re: [MacRuby-devel] Framework callbacks in macirb

2009-02-25 Thread Pedo Borges

Checkout the testing brach from the svn repository.

On Feb 8, 2009, at 12:05 PM, Tedd Fox wrote:


Sorry for the newb question, but how can one upgrade from .3?


On Feb 8, 2009, at 3:14 AM, Vincent Isambart wrote:

Macintosh:vincentisambart-hotconsole- 
cbdd6d06ece482e124516359cd9299294667daeb barry$ macrake
(in /Users/barry/dev/vincentisambart-hotconsole- 
cbdd6d06ece482e124516359cd9299294667daeb)

rake aborted!
no such file to load -- hotcocoa/standard_rake_tasks
/Users/barry/dev/vincentisambart-hotconsole- 
cbdd6d06ece482e124516359cd9299294667daeb/rakefile:2:in `require'

(See full trace by running task with --trace)


This means you are using an old version of MacRuby, probably 0.3. You
can check it by running macruby -v, or in macirb by displaying
MACRUBY_VERSION and MACRUBY_REVISION.
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


[MacRuby-devel] Building Mail.app plugin with MacRuby

2009-02-25 Thread Olexandr Prokhorenko

Sirs,

I'm playing around Mail.app plugin bundles, and I'd like to use  
MacRuby for building a plugin.  However, I can't run it with Mail.app.  
As soon as I'm placing a call to macruby_main(..), I'm getting:


The client that links against MacRuby was not built for GC.

I think Mail.app is not GC-enabled application.  Are there any  
workarounds or all these efforts are pretty much doomed?


Thanks.

--Alexander Prohorenko.

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


[MacRuby-devel] Porting Cocoa OpenGL sample code

2009-02-25 Thread Julien Jassaud

Hello,

I am trying to port the Cocoa OpenGL sample to MacRuby and encountered  
a few problems.



First, I can't access some constants defined in an enum in GLTypes.h.  
Do I need to port those constants to ruby by hand ? Is that related to  
gen_bridge_metadata ?



Second, I need to use CGLQueryRendererInfo and CGLDescribeRenderer  
functions. The first one requires a pointer to a CGLRendererInfoObj  
structure but the second requires the object to be passed directly. I  
tried some C style pointer arithmetic :


info= Pointer.new_with_type("CGLRendererInfoObj")
count   = Pointer.new_with_type("l")

CGLQueryRendererInfo(caps[:cgl_display_mask], info, count) <- works  
fine, but CGLRendererInfoObj is opaque so I can't check it in irb.


CGLDescribeRenderer(info[0], 0, kCGLRPRendererCount, count) <- I  
naively tried to dereference the pointer, but it doesn't work.


CGLDescribeRenderer(info, 0, kCGLRPRendererCount, count) <- No  
complaints, but the value for count[0] is not consistent (100468704  
renderers).


I see in MacIRB that there is a CGLRendererInfoObj class but I can't  
instantiate it.


This is all new to me and I may be overlooking something obvious. If  
anyone has an idea, please help.


Thanks,
Julien Jassaud___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] Framework callbacks in macirb

2009-02-25 Thread Eloy Duran
No, please just use trunk. You can switch the "location" of a  
checkout: http://svnbook.red-bean.com/en/1.0/re27.html


Laurent, should we remove the testing branch, I think it's misleading  
and un-useful atm.


Cheers,
Eloy

On Feb 8, 2009, at 3:43 PM, Pedo Borges wrote:


Checkout the testing brach from the svn repository.

On Feb 8, 2009, at 12:05 PM, Tedd Fox wrote:


Sorry for the newb question, but how can one upgrade from .3?


On Feb 8, 2009, at 3:14 AM, Vincent Isambart wrote:

Macintosh:vincentisambart-hotconsole- 
cbdd6d06ece482e124516359cd9299294667daeb barry$ macrake
(in /Users/barry/dev/vincentisambart-hotconsole- 
cbdd6d06ece482e124516359cd9299294667daeb)

rake aborted!
no such file to load -- hotcocoa/standard_rake_tasks
/Users/barry/dev/vincentisambart-hotconsole- 
cbdd6d06ece482e124516359cd9299294667daeb/rakefile:2:in `require'

(See full trace by running task with --trace)


This means you are using an old version of MacRuby, probably 0.3.  
You

can check it by running macruby -v, or in macirb by displaying
MACRUBY_VERSION and MACRUBY_REVISION.
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] Porting Cocoa OpenGL sample code

2009-02-25 Thread Brian Chapados
CGLRendererInfo is a pointer to a struct:
typedef struct _CGLRendererInfoObject *CGLRendererInfoObj;

try creating a pointer to void or to the struct:

info = Pointer.new_with_type("^v")  # void *info;

or

info = Pointer.new_with_type("^{_CGLRendererInfoObject=}") #
CGLRendererInfo *info

I think the second one is effectively the same as what you were trying
to do with:
info = Pointer.new_with_type("CGLRendererInfoObj")

except that the runtime doesn't know what to do with
"CGLRendererInfo".  The argument to Pointer.new_with_type must be a
valid Objective-C type encoding[1].

[1]: 
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#//apple_ref/doc/uid/TP40008048-CH100-SW1

If you are ever in doubt about what encoding to use, you can always
compile a small Objective-C program that prints out the output of
@encode().  For example:

#import 
#import 

int main(int argc, char *argv[])
{
char *encoding = @encode(CGLRendererInfoObj);
printf("\nencoding => %s\n\n", encoding);
return 0;
}

compile with:
gcc -Wall -o encode encode.m -framework Foundation -framework OpenGL

then run:
./encode

Maybe there is an easier way to obtain the output of @encode(). I'm not sure.

Brian

On Wed, Feb 25, 2009 at 1:42 AM, Julien Jassaud  wrote:
> Hello,
> I am trying to port the Cocoa OpenGL sample to MacRuby and encountered a few
> problems.
>
> First, I can't access some constants defined in an enum in GLTypes.h. Do I
> need to port those constants to ruby by hand ? Is that related
> to gen_bridge_metadata ?
>
> Second, I need to use CGLQueryRendererInfo
> and CGLDescribeRenderer functions. The first one requires a pointer to
> a CGLRendererInfoObj structure but the second requires the object to be
> passed directly. I tried some C style pointer arithmetic :
> info = Pointer.new_with_type("CGLRendererInfoObj")
> count = Pointer.new_with_type("l")
> CGLQueryRendererInfo(caps[:cgl_display_mask], info, count) <- works fine,
> but CGLRendererInfoObj is opaque so I can't check it in irb.
> CGLDescribeRenderer(info[0], 0, kCGLRPRendererCount, count) <- I naively
> tried to dereference the pointer, but it doesn't work.
> CGLDescribeRenderer(info, 0, kCGLRPRendererCount, count) <- No complaints,
> but the value for count[0] is not consistent (100468704 renderers).
> I see in MacIRB that there is a CGLRendererInfoObj class but I
> can't instantiate it.
> This is all new to me and I may be overlooking something obvious. If anyone
> has an idea, please help.
> Thanks,
> Julien Jassaud
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
>
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] Porting Cocoa OpenGL sample code

2009-02-25 Thread Matt Aimonetti
Brian, what's up with this syntax: info =
Pointer.new_with_type("^{_CGLRendererInfoObject=}")
Can you explain: "^{_CGLRendererInfoObject=}"? is that some secret
incantation only known by the MacRuby/Obj overlords?

Thanks,

- Matt


On Wed, Feb 25, 2009 at 10:13 AM, Brian Chapados  wrote:

> CGLRendererInfo is a pointer to a struct:
>typedef struct _CGLRendererInfoObject *CGLRendererInfoObj;
>
> try creating a pointer to void or to the struct:
>
> info = Pointer.new_with_type("^v")  # void *info;
>
> or
>
> info = Pointer.new_with_type("^{_CGLRendererInfoObject=}") #
> CGLRendererInfo *info
>
> I think the second one is effectively the same as what you were trying
> to do with:
> info = Pointer.new_with_type("CGLRendererInfoObj")
>
> except that the runtime doesn't know what to do with
> "CGLRendererInfo".  The argument to Pointer.new_with_type must be a
> valid Objective-C type encoding[1].
>
> [1]:
> http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#//apple_ref/doc/uid/TP40008048-CH100-SW1
>
> If you are ever in doubt about what encoding to use, you can always
> compile a small Objective-C program that prints out the output of
> @encode().  For example:
>
> #import 
> #import 
>
> int main(int argc, char *argv[])
> {
>char *encoding = @encode(CGLRendererInfoObj);
>printf("\nencoding => %s\n\n", encoding);
>return 0;
> }
>
> compile with:
> gcc -Wall -o encode encode.m -framework Foundation -framework OpenGL
>
> then run:
> ./encode
>
> Maybe there is an easier way to obtain the output of @encode(). I'm not
> sure.
>
> Brian
>
> On Wed, Feb 25, 2009 at 1:42 AM, Julien Jassaud 
> wrote:
> > Hello,
> > I am trying to port the Cocoa OpenGL sample to MacRuby and encountered a
> few
> > problems.
> >
> > First, I can't access some constants defined in an enum in GLTypes.h. Do
> I
> > need to port those constants to ruby by hand ? Is that related
> > to gen_bridge_metadata ?
> >
> > Second, I need to use CGLQueryRendererInfo
> > and CGLDescribeRenderer functions. The first one requires a pointer to
> > a CGLRendererInfoObj structure but the second requires the object to be
> > passed directly. I tried some C style pointer arithmetic :
> > info = Pointer.new_with_type("CGLRendererInfoObj")
> > count = Pointer.new_with_type("l")
> > CGLQueryRendererInfo(caps[:cgl_display_mask], info, count) <- works fine,
> > but CGLRendererInfoObj is opaque so I can't check it in irb.
> > CGLDescribeRenderer(info[0], 0, kCGLRPRendererCount, count) <- I naively
> > tried to dereference the pointer, but it doesn't work.
> > CGLDescribeRenderer(info, 0, kCGLRPRendererCount, count) <- No
> complaints,
> > but the value for count[0] is not consistent (100468704 renderers).
> > I see in MacIRB that there is a CGLRendererInfoObj class but I
> > can't instantiate it.
> > This is all new to me and I may be overlooking something obvious. If
> anyone
> > has an idea, please help.
> > Thanks,
> > Julien Jassaud
> > ___
> > MacRuby-devel mailing list
> > [email protected]
> > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> >
> >
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] Building Mail.app plugin with MacRuby

2009-02-25 Thread Matt Aimonetti
Laurent replied via twitter: http://twitter.com/lrz/status/1243876823
The only workarounds would be to rewrite MacRuby to not use the GC, or
Mail.app to use the GC. Very unlikely.


- Matt


On Mon, Feb 23, 2009 at 9:42 PM, Olexandr Prokhorenko
 wrote:
>
> Sirs,
> I'm playing around Mail.app plugin bundles, and I'd like to use MacRuby for 
> building a plugin.  However, I can't run it with Mail.app. As soon as I'm 
> placing a call to macruby_main(..), I'm getting:
> The client that links against MacRuby was not built for GC.
> I think Mail.app is not GC-enabled application.  Are there any workarounds or 
> all these efforts are pretty much doomed?
> Thanks.
>
> --Alexander Prohorenko.
>
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] Porting Cocoa OpenGL sample code

2009-02-25 Thread Brian Chapados
> Can you explain: "^{_CGLRendererInfoObject=}"? is that some secret
> incantation only known by the MacRuby/Obj overlords?

Yes, it is actually a 7th level spell: 'Encode Structure'.  To learn
it, you must study the ancient tome:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#//apple_ref/doc/uid/TP40008048-CH100-SW1

 If it makes you feel better, I usually need to look it up (or just
run the Obj-C code sample), unless it is something simple (like '@').
I don't keep this spell in memory, as it is only required in special
situations.

Seriously though, that is actually how you encode a pointer to a
struct.  If you use the @encode(type) directive, the compiler will
return the runtime encoding for 'type'.  It's a bit cryptic, but not
too bad once you know the syntax:

'^type' encodes a pointer to type.
'{name=...}'
encodes a struct with N fields.

To break it down using 2 examples:

(from the docs)
typedef struct example {
id   anObject; // encoding = @
char *aString; // encoding = c
int  anInt; // enoding = i
} Example;

@encode(Example) = "^{examp...@ci}"

CGLRendererInfoObj is a pointer to an opaque struct (we don't know
anything about the fields) named _CGLRendererInfoObject. All we know
is:
typedef struct _CGLRendererInfoObject *CGLRendererInfoObj;

so it's just "^{_CGLRendererInfoObject=}"

In practice (unless you're working with CoreFoundation C APIs) you
usually just need a pointer to an object.  The most common usage I run
across is to retrieve NSError objects.  The CoreFoundation C API uses
pass-by-reference extensively.  To use these functions with MacRuby,
you need to create lots of pointer objects. In general, this is an
area where interfacing ruby with C is just fugly.  I'd personally
avoid doing this in MacRuby.  If you find yourself needing to use lots
Pointer objects, it's probably better and less error-prone to write
that code in C and expose it to MacRuby through an Objective-C
interface.

That said, for common things, I've used something like this extension
to the Pointer class:


class Pointer
  def self.ptr
new_with_type("@")
  end

  def self.to(type = :object)
case type
  when :object
new_with_type('@')
  when :int
new_with_type('i')
  when :char
  when :bool
  when :BOOL
new_with_type('c')
  when :unsigned
new_with_type('I')
end
  end

  def value
self[0]
  end
end



Need a pointer to an ObjC object?
p = Pointer.ptr

To a BOOL?
p = Pointer.to(:BOOL)

Need the value?
p.value

Those are the most common types I've needed.

On Wed, Feb 25, 2009 at 11:11 AM, Matt Aimonetti
 wrote:
> Brian, what's up with this syntax: info =
> Pointer.new_with_type("^{_CGLRendererInfoObject=}")
> Can you explain: "^{_CGLRendererInfoObject=}"? is that some secret
> incantation only known by the MacRuby/Obj overlords?
> Thanks,
> - Matt
>
> On Wed, Feb 25, 2009 at 10:13 AM, Brian Chapados  wrote:
>>
>> CGLRendererInfo is a pointer to a struct:
>>    typedef struct _CGLRendererInfoObject *CGLRendererInfoObj;
>>
>> try creating a pointer to void or to the struct:
>>
>> info = Pointer.new_with_type("^v")  # void *info;
>>
>> or
>>
>> info = Pointer.new_with_type("^{_CGLRendererInfoObject=}") #
>> CGLRendererInfo *info
>>
>> I think the second one is effectively the same as what you were trying
>> to do with:
>> info = Pointer.new_with_type("CGLRendererInfoObj")
>>
>> except that the runtime doesn't know what to do with
>> "CGLRendererInfo".  The argument to Pointer.new_with_type must be a
>> valid Objective-C type encoding[1].
>>
>> [1]:
>> http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#//apple_ref/doc/uid/TP40008048-CH100-SW1
>>
>> If you are ever in doubt about what encoding to use, you can always
>> compile a small Objective-C program that prints out the output of
>> @encode().  For example:
>>
>> #import 
>> #import 
>>
>> int main(int argc, char *argv[])
>> {
>>    char *encoding = @encode(CGLRendererInfoObj);
>>    printf("\nencoding => %s\n\n", encoding);
>>    return 0;
>> }
>>
>> compile with:
>> gcc -Wall -o encode encode.m -framework Foundation -framework OpenGL
>>
>> then run:
>> ./encode
>>
>> Maybe there is an easier way to obtain the output of @encode(). I'm not
>> sure.
>>
>> Brian
>>
>> On Wed, Feb 25, 2009 at 1:42 AM, Julien Jassaud 
>> wrote:
>> > Hello,
>> > I am trying to port the Cocoa OpenGL sample to MacRuby and encountered a
>> > few
>> > problems.
>> >
>> > First, I can't access some constants defined in an enum in GLTypes.h. Do
>> > I
>> > need to port those constants to ruby by hand ? Is that related
>> > to gen_bridge_metadata ?
>> >
>> > Second, I need to use CGLQueryRendererInfo
>> > and CGLDescribeRenderer functions. The first one requires a pointer to
>> > a CGLRendererInfoObj structure but the second requires the object to be
>> > passed directly. I tried some C sty

Re: [MacRuby-devel] Porting Cocoa OpenGL sample code

2009-02-25 Thread Matt Aimonetti
Thanks Brian for the detailed explanation. I wonder if your Pointer
extension shouldn't be merged into HotCocoa or MacRuby itself.

What do you guys think?

- Matt

On Wed, Feb 25, 2009 at 12:43 PM, Brian Chapados  wrote:
>> Can you explain: "^{_CGLRendererInfoObject=}"? is that some secret
>> incantation only known by the MacRuby/Obj overlords?
>
> Yes, it is actually a 7th level spell: 'Encode Structure'.  To learn
> it, you must study the ancient tome:
> http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#//apple_ref/doc/uid/TP40008048-CH100-SW1
>
>  If it makes you feel better, I usually need to look it up (or just
> run the Obj-C code sample), unless it is something simple (like '@').
> I don't keep this spell in memory, as it is only required in special
> situations.
>
> Seriously though, that is actually how you encode a pointer to a
> struct.  If you use the @encode(type) directive, the compiler will
> return the runtime encoding for 'type'.  It's a bit cryptic, but not
> too bad once you know the syntax:
>
> '^type' encodes a pointer to type.
> '{name=...}'
> encodes a struct with N fields.
>
> To break it down using 2 examples:
>
> (from the docs)
> typedef struct example {
>    id   anObject; // encoding = @
>    char *aString; // encoding = c
>    int  anInt; // enoding = i
> } Example;
>
> @encode(Example) = "^{examp...@ci}"
>
> CGLRendererInfoObj is a pointer to an opaque struct (we don't know
> anything about the fields) named _CGLRendererInfoObject. All we know
> is:
> typedef struct _CGLRendererInfoObject *CGLRendererInfoObj;
>
> so it's just "^{_CGLRendererInfoObject=}"
>
> In practice (unless you're working with CoreFoundation C APIs) you
> usually just need a pointer to an object.  The most common usage I run
> across is to retrieve NSError objects.  The CoreFoundation C API uses
> pass-by-reference extensively.  To use these functions with MacRuby,
> you need to create lots of pointer objects. In general, this is an
> area where interfacing ruby with C is just fugly.  I'd personally
> avoid doing this in MacRuby.  If you find yourself needing to use lots
> Pointer objects, it's probably better and less error-prone to write
> that code in C and expose it to MacRuby through an Objective-C
> interface.
>
> That said, for common things, I've used something like this extension
> to the Pointer class:
>
> 
> class Pointer
>  def self.ptr
>    new_with_type("@")
>  end
>
>  def self.to(type = :object)
>    case type
>      when :object
>        new_with_type('@')
>      when :int
>        new_with_type('i')
>      when :char
>      when :bool
>      when :BOOL
>        new_with_type('c')
>      when :unsigned
>        new_with_type('I')
>    end
>  end
>
>  def value
>    self[0]
>  end
> end
>
> 
>
> Need a pointer to an ObjC object?
> p = Pointer.ptr
>
> To a BOOL?
> p = Pointer.to(:BOOL)
>
> Need the value?
> p.value
>
> Those are the most common types I've needed.
>
> On Wed, Feb 25, 2009 at 11:11 AM, Matt Aimonetti
>  wrote:
>> Brian, what's up with this syntax: info =
>> Pointer.new_with_type("^{_CGLRendererInfoObject=}")
>> Can you explain: "^{_CGLRendererInfoObject=}"? is that some secret
>> incantation only known by the MacRuby/Obj overlords?
>> Thanks,
>> - Matt
>>
>> On Wed, Feb 25, 2009 at 10:13 AM, Brian Chapados  wrote:
>>>
>>> CGLRendererInfo is a pointer to a struct:
>>>    typedef struct _CGLRendererInfoObject *CGLRendererInfoObj;
>>>
>>> try creating a pointer to void or to the struct:
>>>
>>> info = Pointer.new_with_type("^v")  # void *info;
>>>
>>> or
>>>
>>> info = Pointer.new_with_type("^{_CGLRendererInfoObject=}") #
>>> CGLRendererInfo *info
>>>
>>> I think the second one is effectively the same as what you were trying
>>> to do with:
>>> info = Pointer.new_with_type("CGLRendererInfoObj")
>>>
>>> except that the runtime doesn't know what to do with
>>> "CGLRendererInfo".  The argument to Pointer.new_with_type must be a
>>> valid Objective-C type encoding[1].
>>>
>>> [1]:
>>> http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#//apple_ref/doc/uid/TP40008048-CH100-SW1
>>>
>>> If you are ever in doubt about what encoding to use, you can always
>>> compile a small Objective-C program that prints out the output of
>>> @encode().  For example:
>>>
>>> #import 
>>> #import 
>>>
>>> int main(int argc, char *argv[])
>>> {
>>>    char *encoding = @encode(CGLRendererInfoObj);
>>>    printf("\nencoding => %s\n\n", encoding);
>>>    return 0;
>>> }
>>>
>>> compile with:
>>> gcc -Wall -o encode encode.m -framework Foundation -framework OpenGL
>>>
>>> then run:
>>> ./encode
>>>
>>> Maybe there is an easier way to obtain the output of @encode(). I'm not
>>> sure.
>>>
>>> Brian
>>>
>>> On Wed, Feb 25, 2009 at 1:42 AM, Julien Jassaud 
>>> wrote:
>>> > Hello,
>>> > I am trying to port the Cocoa OpenGL sample to MacRuby and encountered a
>>> > few
>>> > problems.
>>> >

Re: [MacRuby-devel] Porting Cocoa OpenGL sample code

2009-02-25 Thread Laurent Sansonetti
That's a pretty good idea. I tried to make the Pointer class as simple  
(and stupid) as possible but we might need some convenience APIs on  
top of it, for those not familiar with the Objective-C encoding types.


Here is an API proposal based on Brian's snippet... thoughts?

class Pointer
  def self.new(type='@')
new_with_type(type)
  end
  TYPES = {
   :int => 'i',
   :uint => 'I',
   ...
  }
  def self.to(sym)
new_with_type(TYPES[sym])
  end
  def value
self[0]
  end
end

# I'm pretty sure I already wrote something similar in RubyCocoa.

Laurent

On Feb 25, 2009, at 1:16 PM, Matt Aimonetti wrote:


Thanks Brian for the detailed explanation. I wonder if your Pointer
extension shouldn't be merged into HotCocoa or MacRuby itself.

What do you guys think?

- Matt

On Wed, Feb 25, 2009 at 12:43 PM, Brian Chapados   
wrote:

Can you explain: "^{_CGLRendererInfoObject=}"? is that some secret
incantation only known by the MacRuby/Obj overlords?


Yes, it is actually a 7th level spell: 'Encode Structure'.  To learn
it, you must study the ancient tome:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#/ 
/apple_ref/doc/uid/TP40008048-CH100-SW1


 If it makes you feel better, I usually need to look it up (or just
run the Obj-C code sample), unless it is something simple (like '@').
I don't keep this spell in memory, as it is only required in special
situations.

Seriously though, that is actually how you encode a pointer to a
struct.  If you use the @encode(type) directive, the compiler will
return the runtime encoding for 'type'.  It's a bit cryptic, but not
too bad once you know the syntax:

'^type' encodes a pointer to type.
'{name=...}'
encodes a struct with N fields.

To break it down using 2 examples:

(from the docs)
typedef struct example {
   id   anObject; // encoding = @
   char *aString; // encoding = c
   int  anInt; // enoding = i
} Example;

@encode(Example) = "^{examp...@ci}"

CGLRendererInfoObj is a pointer to an opaque struct (we don't know
anything about the fields) named _CGLRendererInfoObject. All we know
is:
typedef struct _CGLRendererInfoObject *CGLRendererInfoObj;

so it's just "^{_CGLRendererInfoObject=}"

In practice (unless you're working with CoreFoundation C APIs) you
usually just need a pointer to an object.  The most common usage I  
run

across is to retrieve NSError objects.  The CoreFoundation C API uses
pass-by-reference extensively.  To use these functions with MacRuby,
you need to create lots of pointer objects. In general, this is an
area where interfacing ruby with C is just fugly.  I'd personally
avoid doing this in MacRuby.  If you find yourself needing to use  
lots

Pointer objects, it's probably better and less error-prone to write
that code in C and expose it to MacRuby through an Objective-C
interface.

That said, for common things, I've used something like this extension
to the Pointer class:


class Pointer
 def self.ptr
   new_with_type("@")
 end

 def self.to(type = :object)
   case type
 when :object
   new_with_type('@')
 when :int
   new_with_type('i')
 when :char
 when :bool
 when :BOOL
   new_with_type('c')
 when :unsigned
   new_with_type('I')
   end
 end

 def value
   self[0]
 end
end



Need a pointer to an ObjC object?
p = Pointer.ptr

To a BOOL?
p = Pointer.to(:BOOL)

Need the value?
p.value

Those are the most common types I've needed.

On Wed, Feb 25, 2009 at 11:11 AM, Matt Aimonetti
 wrote:

Brian, what's up with this syntax: info =
Pointer.new_with_type("^{_CGLRendererInfoObject=}")
Can you explain: "^{_CGLRendererInfoObject=}"? is that some secret
incantation only known by the MacRuby/Obj overlords?
Thanks,
- Matt

On Wed, Feb 25, 2009 at 10:13 AM, Brian Chapados  
 wrote:


CGLRendererInfo is a pointer to a struct:
   typedef struct _CGLRendererInfoObject *CGLRendererInfoObj;

try creating a pointer to void or to the struct:

info = Pointer.new_with_type("^v")  # void *info;

or

info = Pointer.new_with_type("^{_CGLRendererInfoObject=}") #
CGLRendererInfo *info

I think the second one is effectively the same as what you were  
trying

to do with:
info = Pointer.new_with_type("CGLRendererInfoObj")

except that the runtime doesn't know what to do with
"CGLRendererInfo".  The argument to Pointer.new_with_type must be a
valid Objective-C type encoding[1].

[1]:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#/ 
/apple_ref/doc/uid/TP40008048-CH100-SW1


If you are ever in doubt about what encoding to use, you can always
compile a small Objective-C program that prints out the output of
@encode().  For example:

#import 
#import 

int main(int argc, char *argv[])
{
   char *encoding = @encode(CGLRendererInfoObj);
   printf("\nencoding => %s\n\n", encoding);
   return 0;
}

compile with:
gcc -Wall -o encode encode.m -framework Foundation -framework  
OpenGL


then run:
./encode

Re: [MacRuby-devel] Framework callbacks in macirb

2009-02-25 Thread Laurent Sansonetti
Agreed. I just removed it and appropriately changed the wiki to not  
mention it anymore.


Laurent

On Feb 25, 2009, at 3:34 AM, Eloy Duran wrote:

No, please just use trunk. You can switch the "location" of a  
checkout: http://svnbook.red-bean.com/en/1.0/re27.html


Laurent, should we remove the testing branch, I think it's  
misleading and un-useful atm.


Cheers,
Eloy

On Feb 8, 2009, at 3:43 PM, Pedo Borges wrote:


Checkout the testing brach from the svn repository.

On Feb 8, 2009, at 12:05 PM, Tedd Fox wrote:


Sorry for the newb question, but how can one upgrade from .3?


On Feb 8, 2009, at 3:14 AM, Vincent Isambart wrote:

Macintosh:vincentisambart-hotconsole- 
cbdd6d06ece482e124516359cd9299294667daeb barry$ macrake
(in /Users/barry/dev/vincentisambart-hotconsole- 
cbdd6d06ece482e124516359cd9299294667daeb)

rake aborted!
no such file to load -- hotcocoa/standard_rake_tasks
/Users/barry/dev/vincentisambart-hotconsole- 
cbdd6d06ece482e124516359cd9299294667daeb/rakefile:2:in `require'

(See full trace by running task with --trace)


This means you are using an old version of MacRuby, probably 0.3.  
You

can check it by running macruby -v, or in macirb by displaying
MACRUBY_VERSION and MACRUBY_REVISION.
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel