Re: [MacRuby-devel] Bindings only working one-way

2008-11-22 Thread John Shea

Hi Michael,

I too have difficulties with IB and bindings - mainly because they are  
hard to debug - well I find them so (and not just in MacRuby).


When in doubt I blame an IB setting.

I quickly threw together something similar to what you have (except  
with sliders) , and pretty quickly came to the conclusion that it was  
not working ;-) - as soon as I embedded my working object into a  
matrix the KVO stopped working.


 I could get it working quickly sans matrix.

For morale and momentum I would suggest you get things working without  
the matrix first.


Using MacRuby attr_accessor (at least in my experience) will give you  
all the kvo magic but if you have a manual changing of the observed  
value you have to use the given (implicit) setter.


for example:
attr_accessor :billy # will create setter and getter for billy with  
all the appropritate KVO methods


def updateMyValue(sender) #called from a button perhaps
setBilly(4)
end

#or setValue:4 forKey:billy

[EMAIL PROTECTED] = 4 will not work, because it bypasses the accessor methods


So you don't need to override the accessors unless you are doing some  
additional work.


If you do override the accessors then you will have to put the whole  
willChangeValueForKey, and didChangeValueForKey  calls in your  
overwritten method.
In your code below you do override the accessor, and therefore lose  
the KVO.


If you are getting stuck on the simplest of binding I can send you a  
small project adapted from Hillegass which has an example of KVC.


Re matrix difficulties, a more experienced Cocoa person than me must  
proffer an explanation ;-).


Hope that helps,
cheers,
John

On Nov 22, 2008, at 1:01 AM, Michael Winterstein wrote:

I'm having difficulty working with bindings and I'm not sure if it's  
a MacRuby thing or my poor understanding of how they work.


I've tried binding to two types of things - an NSMatrix of radio  
buttons (binding to "selectedTag") and a Checkbox value.


Using just an attr_accessor - the variable changes when the user  
changes them, but changing the variable doesn't update in the UI.


So I added an explicit setter method and to change the variable, I  
use self.setVideoSource(VID_USE_S2) to modify it.


This works to change it on-screen, but now UI changes aren't getting  
through to the variables properly.  The NSMatrix variable isn't  
changing, and the other variables are changing but are no longer  
Boolean.  (If I do a "p x" I get  either #  
or #.


I tried replacing 'attr_accessor' with 'attr_reader', and adding an  
explicit getter. That results in the following when I run (even if I  
add a 'return nil' to my setter method):


[4169:10b] KVO autonotifying only supports -set: methods that  
return void. Autonotifying will not be done for invocations of - 
[MainWinController setVideoSource:].


I haven't yet tried manual notification because I'm not likely to  
use bindings for this case if that much work is required.  Is this  
the expected way to go, or am I missing something here?




Here's a bit of the code (these are set as keys in IB).  When used  
elsewhere, I just have them as the instance variable :


attr_accessor   :audioIncludeS1 # whether to include audio
attr_accessor   :audioIncludeS2 # for a particular channel
attr_accessor   	:videoSource		# which source to use (if any) for  
video


def setAudioIncludeS1(value)
@audioIncludeS1 = value
end

def setAudioIncludeS2(value)
@audioIncludeS2 = value
end


def setVideoSource(value)
case value
when VID_USE_S1
@videoSource = VID_USE_S1
when VID_USE_S2
@videoSource = VID_USE_S2
when VID_USE_NONE
@videoSource = VID_USE_NONE
else
@videoSource = VID_USE_NONE
end
end

___
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] MacRuby talk at the San Francisco Ruby MeetUp, 12/11

2008-11-26 Thread John Shea

The RubyConf talk is up on confreaks too, for those of us not in the US:

http://rubyconf2008.confreaks.com/macruby-ruby-for-your-mac.html

J
On Nov 26, 2008, at 9:57 PM, Rich Morin wrote:


FYI...

 Laurent Sansonetti of Apple will reprise his RubyConf 2008
 talk on MacRuby, a version of Ruby 1.9 that makes convenient
 and efficient use of Mac OS X core technologies such as the
 Objective-C common runtime and garbage collector, and the
 CoreFoundation framework.


 --  http://www.meetup.com/sfruby/calendar/8841115/

-r


P.S.  I'm collecting names of folks who would like to attend
 a Bay Area MacRuby hackfest (aimed at app developers).
 Drop me a line if you're interested...
--
http://www.cfcl.com/rdmRich Morin
http://www.cfcl.com/rdm/resume [EMAIL PROTECTED]
http://www.cfcl.com/rdm/weblog +1 650-873-7841

Technical editing and writing, programming, and web development
___
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] sub classing with hot cocoa

2008-11-29 Thread John Shea

Hi folks,

I am sure there is an easy answer to this question, but I have not  
figured it out after some experimenting (nor can I find an example in  
the examples)


What do I do if i want to subclass (say) an NSView ? And yet still  
employ that subclass with all the rest of the hot cocoa magic? (so  
without using nib/xibs)


I would do this to overwrite the drawRect callback for NSView for  
example - perhaps to do some animation.


Thanks in advance,
John

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


Re: [MacRuby-devel] pointer to a pointer

2008-12-01 Thread John Shea

Hi Yehuda,

Laurent kindly responded to a similar query from me :

His reply (Novemebr 24th):

In order to use these methods I introduced in trunk a class named  
Pointer. You allocate a Pointer object by using the #new_with_type  
method in which you pass the Objective-C type encoding.  @ is for  
pointers, i for integers, d for doubles, etc...


# This is not very intuitive, I will implement the RubyCocoa way to  
deal with pointers as well.


You use it like that:

errorp = Pointer.new_with_type('@')
   urlData = NSURLConnection.sendSynchronousRequest(urlRequest,  
returningResponse:response, error:errorp)

   if urlData.nil?
 error = errorp[0]
 puts "error: #{error.description}"
  end



With trunk of last week it worked fine for me with:

errorp = Pointer.new_with_type('@')
response = Pointer.new_with_type("@")

urlData = NSURLConnection.sendSynchronousRequest(urlRequest,  
returningResponse:response, error:errorp)


Hope that helps,
cheers,
J




On Dec 1, 2008, at 8:30 , Yehuda Katz wrote:

I'm trying to figure out a way to make an NSError** object that is a  
required parameter to the PSFeed#refresh: method. What's the correct  
mechanism?


--
Yehuda Katz
Developer | Engine Yard
(ph) 718.877.1325
___
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] sub classing with hot cocoa

2008-12-02 Thread John Shea

Hi Ben,
thanks for your answer.

I tried that initially, but my subclass was having problems being  
added to the layout view.


Anyway - somehow I got something going a little further - the  
important thing was to have a create method which has :  
alloc.initWithFrame([0, 0, *GameSize]) in my NSView subclass...


I did not get much further than painting black (transparency etc did  
not work) - but its on the back burner while I experiment a bit more  
with plain MacRuby.


Cheers and thanks,
John

On Dec 2, 2008, at 10:37 PM, Benjamin Stiglitz wrote:

I am sure there is an easy answer to this question, but I have not  
figured it out after some experimenting (nor can I find an example  
in the examples)


What do I do if i want to subclass (say) an NSView ? And yet still  
employ that subclass with all the rest of the hot cocoa magic? (so  
without using nib/xibs)


I would do this to overwrite the drawRect callback for NSView for  
example - perhaps to do some animation.


class MyView < NSView
 def drawRect(r)

 end
end

or, even better in some cases

a = view(:something)
class << a
 def drawRect(r)

 end
end

-Ben
___
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] HotCocoa Part I

2008-12-02 Thread John Shea
I think its interesting that Hot Cocoa in inspiring such different  
ideas, I must admit my thoughts had not run anywhere as complex as  
those below.


My first thought was "Wow! I can make a generic (or  fairly static)  
launcher and get it to load remotely both my view and model from ruby  
files! Thats my RIA issue solved!"


I experimented and sure enough I could deliver to my client (me in  
this experiment ;-) ) rapidly changing versions of a beautiful GUI app  
(1 button) by only changing the source file on the server.


But maybe this is "old hat"?

J


On Dec 2, 2008, at 11:48 PM, Rich Morin wrote:


At 10:10 -0500 11/12/08, Richard Kilmer wrote:

"HotCocoa is an idiomatic Ruby API that simplifies the configuration
and wiring together of complex ObjC/Cocoa classes."

I realize this will not be all things to all people, and that some
may not see the much value in this. I do, and I think that HotCocoa
should NOT try and be all things to all people.  Let me even get
more specific.  I don't think that HotCocoa should strive to contain
simplifications for all frameworks in Cocoa.

If core audio needs to be simplified though a wonderful Ruby API
then it should be done with a wonderful Ruby API, but that is not
HotCocoa, its a core audio MacRuby library.  Something that uses
HotCocoa could also use that wonderfully simplified core audio
library.  To try and say every simplified use of ObjC frameworks is
included in HotCocoa creates a truly unwieldy beast.


It's clear that HC provides a lot of useful infrastructure for making
Cocoa programming more palatable to Rubyists.  More to the point, it
makes it easy for developers to create even more useful  
infrastructure.


A large part of HC's value lies in the fact that it's so easy to wrap
ObjC and Cocoa goo in nice Rubyish idioms.  This encourages HC users  
to
create frameworks as they go along.  Encounter an obnoxious API,  
write a

framework to wrap it, then get on with creating the app...

Consequently, IMHO, the question of whether HC _should_ include  
zillions
of random frameworks is rather off the mark.  Clearly, if HC becomes  
even
slightly popular, community members _will_ be creating these  
frameworks.


The critical question, then, is how to create an environment that  
allows
(nay, encourages!) frameworks to be created, tested, polished,  
documented,
indexed, shared, etc.  My intuition is that GitHub should be part of  
this,
because it promotes free-flowing cooperation, merging, etc.   
However, I'm
quite sure that GitHub isn't the entire solution.  So, ideas are  
welcome!


-r


P.S.

One specific suggestion is that there should be a set of guidelines  
for
framework creation.  That is, how do I tell if I'm creating my  
framework

in a manner that will be usable by other developers, similar in style,
etc?  Some of this can be gleaned from perusal of the code, to be  
sure,

but explicit guidelines can help to make things clearer...
--
http://www.cfcl.com/rdmRich Morin
http://www.cfcl.com/rdm/resume [EMAIL PROTECTED]
http://www.cfcl.com/rdm/weblog +1 650-873-7841

Technical editing and writing, programming, and web development
___
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] printing

2008-12-03 Thread John Shea

Hello all,

has anyone done any printing in MacRuby?

I can get it to print ok - if I select the page range, otherwise the  
print routine wants to print thousands (or more - i got scared and  
stopped it) pages.


The rectForPage and the drawRect get called those thousands of times -  
even though the range should be 1 page.


I suspect that the issue is in the knowsRangePage - it is passed a  
pointer.


I de reference the pointer with range = range_pointer[0]  (which does  
give me a range) and then set values with range.location = etc, etc

(rather than range_pointer->location  =  1 , in Objective C)

My suspicion is that although i set the range length and location that  
in fact it is not changing the original pointer appropriately, but  
perhaps inappropriately ;-) with a very large number (a memory address  
perhaps?).


Anyone else had this issue?

cheers and thanks,
John


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


Re: [MacRuby-devel] printing

2008-12-03 Thread John Shea

That was it - the assign statement. Thanks very much!

I just assumed I was getting the object and not a copy ..

(and sorry I should have checked the samples first)

Cheers and thanks,
J


On Dec 3, 2008, at 23:00 , Laurent Sansonetti wrote:


Hi John,

On Dec 3, 2008, at 8:45 AM, John Shea wrote:


Hello all,

has anyone done any printing in MacRuby?


Some examples that ship with MacRuby (such as PathDemo or  
PagePacker) implement a printing facility. I don't really remember  
how it's implemented but maybe this can help you.


I can get it to print ok - if I select the page range, otherwise  
the print routine wants to print thousands (or more - i got scared  
and stopped it) pages.


The rectForPage and the drawRect get called those thousands of  
times - even though the range should be 1 page.


I suspect that the issue is in the knowsRangePage - it is passed a  
pointer.


I de reference the pointer with range = range_pointer[0]  (which  
does give me a range) and then set values with range.location =  
etc, etc

(rather than range_pointer->location  =  1 , in Objective C)


range_pointer[0] will return you a completely new NSRange object. If  
you alter the object it's not going to alter the range_pointer object.


Do you re-assign the object back to the pointer?

r = range_pointer[0]
r.location += 1
range_pointer.assign(r)

My suspicion is that although i set the range length and location  
that in fact it is not changing the original pointer appropriately,  
but perhaps inappropriately ;-) with a very large number (a memory  
address perhaps?).


Anyone else had this issue?


Otherwise, could you share with us a sample project that reproduces  
the problem? Maybe it's a bug in MacRuby.


Laurent
___
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] GLUT (second time around)

2008-12-14 Thread John Shea

(I accidently sent this from the wrong email account initially)

Hello everyone,

Anyone done any macruby opengl?

I am trying to get Hillegass's opengl example going in MacRuby.

My MacRuby version falls over in the drawRect method of an  
NSOpenGLView subclass, when it hits the glut function calls.


eg: glutSolidTorus(0.3, 1.8, 35 , 31)

It does not have problems with previous open gl methods/functions eg:

  def drawRect(r)
glClearColor(0.2, 0.4, 0.1, 0.0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity
gluLookAt(@radius * Math::sin(@theta), 0, @radius *  
Math::cos(@theta), 0,0,0,0,1,0)


lightPosition = [...@lightx, 1, 3, 0.0]
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition)

if !...@displaylist
  @displayList = glGenLists(1)
  glNewList(@displayList, GL_COMPILE_AND_EXECUTE)

  glTranslatef(0,0,0)
  glutSolidTorus(0.3, 1.8, 35 , 31) <= error occurs here   
`drawRect': undefined local variable or method `glut' for #0x10df210> (NameError)



I am actually uncertain whether it is a MacRuby issue or just that I  
am not loading the glut framework or requiring it properly or  
something else.


Both the OpenGL and GLUT frameworks are in the Xcode project , and i  
do the framework calls:


framework 'Cocoa'
framework 'OpenGL'
framework 'GLUT'

in rb_main.rb. Though in fact it seems to not fall over any earlier if  
i remove the last two framework calls.


I am using macruby version 766.

Any ideas?

cheers and thanks,
John


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


Re: [MacRuby-devel] Exposing c structs and functions

2008-12-18 Thread John Shea
Hi Jim,looks like no one who really knows this stuff is offering anything -
so I will suggest some of my naive solutions / possibilities:

- as far as I know C functions, structs etc are brought into macruby by the
bridgesupport project: http://bridgesupport.macosforge.org/trac/ - however I
cannot seem to find much information on it - however they do their stuff,
you could copy - if you could find some docs ;-)

- you could just use C in ruby the normal way via the inline gem
http://www.zenspider.com/ZSS/Products/RubyInline/ - works for me so far with
simple stuff. I thought I read somewhere you could also use Objective C with
this gem - but I cannot find anything on google at the moment.

- or you could proxy through a custom objective C class - eg I managed to
proxy some opengl function calls (not that there is a need to if you have a
NSOpenGLView class - it was more a proof of concept) - alas it failed when
calling GLUT functions (malloc errors).

Hope one of those helps you, I would be curious as to how you finally do it.
Cheers,
John

On Thu, Dec 18, 2008 at 4:29 PM, Jim Getzen  wrote:

> Is there a way to expose some c structs and functions from a custom
> Objective-C framework to MacRuby?
>
> For instance, in my framework I have a 3-D point struct, such as:
> typedef struct {
>CGFloat x, y, z;
> } JPoint3;
>
> In addition, I have creation functions such as 'JPoint3Make(x, y, z)' etc.
>
> How do I make these usable from MacRuby, like NSPoint and NSMakePoint are?
>
> Jim
> ___
> 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] Exposing c structs and functions : Addendum

2008-12-18 Thread John Shea
Hi again Jim,
another note, down the bottom of the MacRuby tutorial
http://www.macruby.org/trac/wiki/MacRubyTutorial, you will see the words:

"On some occasions. you will want to load bridge support files that you
personally generated using gen_bridge_metadata(1). To do that, you can use
the Kernel#load_bridge_support_file method."

And then an example follows, perhaps that will work for you.
Best of luck,
John

On Thu, Dec 18, 2008 at 4:29 PM, Jim Getzen  wrote:

> Is there a way to expose some c structs and functions from a custom
> Objective-C framework to MacRuby?
>
> For instance, in my framework I have a 3-D point struct, such as:
> typedef struct {
>CGFloat x, y, z;
> } JPoint3;
>
> In addition, I have creation functions such as 'JPoint3Make(x, y, z)' etc.
>
> How do I make these usable from MacRuby, like NSPoint and NSMakePoint are?
>
> Jim
> ___
> 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] Pointer to memory. was: Pointers for BOOL types

2009-01-02 Thread John Shea

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  wrote:
Cheque it: http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#/ 
/apple_ref/doc/uid/TP40008048-CH100-SW1


see also: /usr/include/objc/runtime.h

Dave
___
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] Pointer to memory. was: Pointers for BOOL types

2009-01-09 Thread John Shea
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  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  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  wrote:
> >
> > Cheque it:
> >
> http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#//apple_ref/doc/uid/TP40008048-CH100-SW1
> >
> > see also: /usr/include/objc/runtime.h
> >
> > Dave
> > ___
> > 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] Pointer to memory. was: Pointers for BOOL types

2009-01-09 Thread John Shea

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   
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   
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   
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  wrote:

Cheque it:

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


see also: /usr/include/objc/runtime.h

Dave
___
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


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


Re: [MacRuby-devel] Is this the right list?

2009-01-12 Thread John Shea

textView seems rather tedious compared to textField to me.

Here is what I do (which does work when the view is made not editable):

class Controller
attr_writer :text_view #linked to the IB textView on your window

def awakeFromNib
  replace_all_range = NSRange.new(0, @text_view.textStorage.length)
	  @text_view.replaceCharactersInRange(replace_all_range,  
withString:"a new string")

end

end

I saw this originally when learning Ruby / Cocoa  in Brian Marick's  
RubyCocoa book - which is available at the moment as a PDF (it has not  
been released yet to paper I believe) from the Pragmatic Programmers.
Both Marick's and Hillegas's books are important reads for the  
beginning (eg me) macruby programmer.


Cheers,
J



On Jan 13, 2009, at 1:22 AM, Eloy Duran wrote:

How about @text_view.setString("foo") or as @text_view.string =  
"foo" ?


http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSText_Class/Reference/Reference.html#/ 
/apple_ref/doc/uid/2367-setString_


- Eloy

On 13 jan 2009, at 00:46, Timothy McDowell wrote:

Y'know what, that doesn't seem to work actually. No '<<' method,  
and setCharacters/setWords works, but nothing shows up.


On Mon, Jan 12, 2009 at 4:34 PM, Timothy McDowell > wrote:

Haha, I scoured that documentation for an hour! Thanks a bunch. ^_^


On Mon, Jan 12, 2009 at 4:16 PM, Vincent Isambart > wrote:


:textview is linked to an NSTextView object via InterfaceBuilder.  
Now the purpose of this view is to work as the display for text  
coming from a MUD (Multi-user domain/dungeon). I have it set to  
noneditable but selectable. My above code doesn't work. I allow it  
to be editable, and the code does work. Is there a way to prevent  
user-editing but to allow my code to edit it?


Extract from Apple's Objective-C insertText: documentation:
This method is the entry point for inserting text typed by the user  
and is generally not suitable for other purposes. Programmatic  
modification of the text is best done by operating on the text  
storage directly. Because this method pertains to the actions of  
the user, the text view must be editable for the insertion to work.


You can do for instance
@text_view.textStorage << 'my text'
But be careful, text inserted like this ignores the current font  
attributes of the text view. You have to add them yourself.


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



-- Thanks, 
--Zonbi.




--
--Brains.
___
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] Distributing apps with MacRuby.framework

2009-01-23 Thread John Shea

Did someone answer this one - and I missed it?

I too am interested in what the current way to do this is.

Cheers,
J


On Jan 22, 2009, at 7:31 , Dr Nic Williams wrote:


I recently shared a MacRuby app with a friend, with MacRuby.framework
included in the .app via a Copy Files target; but the app died on his
machine complaining that /Library/Frameworks/MacRuby.framework wasn't
available. How do I get the app to use the framework in the .app
bundle?

Nic

--
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
[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] Learning & MacRuby ecosystem, was: Framework callbacks in macirb

2009-02-09 Thread John Shea

Have to agree with Brian regarding Hillegass.

You can compare with my examples here : (http://www.johnmacshea.org/examples/ 
 - which i will try to keep mirrored here:http://idisk.mac.com/johnmshea-Public?view=web 
  since i may turn my mac mini off when i go on holidays).


I would suggest trying to solve them yourself first, perhaps take as a  
challenge the ones I failed to do.


Alternatively you could do something more challenging and broaden the  
MacRuby example ecosystem.


Like what about :
- translating the Cocoa book at the Pragmatic Programmers 
(http://www.pragprog.com/titles/dscpq/cocoa-programming)?

- or even the FXRuby book there (http://www.pragprog.com/titles/fxruby/fxruby)?

- there is a pdf book called Flexible Rails (http://www.flexiblerails.com/ 
) using Flex obviously as the GUI - I had a quick look and I think (I  
have done a bit of Flex before) - it would be far easier in MacRuby.


- why the lucky stiff's shoe examples (http://the-shoebox.org/)?
 For that I don't expect you could get the same succinctness of code  
unless you create a similar DSL layer like _why has for his shoes, but  
these examples might be a good showcase for HotCocoa.


Cheers,
J





On Feb 9, 2009, at 6:56 PM, Brian Chapados wrote:


It is well worth your time to learn the basics of C and Objective-C,
even if your ultimate goal is to mainly use MacRuby
(http://www.joelonsoftware.com/articles/LeakyAbstractions.html ect.).
They are small languages, and everything you need is covered in about
200 pages[1,2]. The cocoa libraries are vast, but powerful and the
documentation is decent. The Hillegass book[3] will bring you up to
speed on how to use the libraries and tools to build gui apps. Once
you understand some of the basic patterns and conventions that are
used, you'll have all of the available cocoa info at your disposal.

For Obj-C/Cocoa/Ruby, I recommend these references:

C/Obj-C/Cocoa

[1] "The C Programming Language", Kernighan & Ritchie
[2] "Introduction to The Objective-C 2.0 Programming Language", Apple
(free online)
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/chapter_1_section_1.html
[3] "Cocoa Programming for Mac OSX", Hillegass

Start with 3 and refer back to 1 & 2, when necessary.  Buy a copy of
Hillegass' book, then clone Dr. Nic's hillegass-macruby repo
(http://github.com/drnic/hillegass-macruby/tree/master). Work on
porting the examples from Objective-C to MacRuby.

You might also want to check out these recommendations:
http://programming.nu/objective-c

Ruby
---
"Programming Ruby" (Pickaxe book) Thomas
"The Ruby Way", Fulton

For Ruby idioms, there is also an excellent SDRuby talk by Tom Werner
on Ruby Idioms:
http://podcast.sdruby.com/2007/1/16/episode-014-ruby-idioms-part-1

Slides from a 2003 talk by Hal Fulton - "Rubyesque API":
http://www.approximity.com/euruko03/slides/hal/rubyesque/slide1.html

On Sun, Feb 8, 2009 at 8:28 PM, Robert Schaaf   
wrote:

Tedd,

To quote Ogden Nash, I'm a stranger here myself.

I agree about objective-c; it's notationally unattractive.  It  
seems to be

an uncomfortable hybrid, despite the power of the object model.

The only appreciable Ruby code I've written is a program that  
parses the

header of a DB2 IXF file (a database dump) and loads it into Excel
preserving data types.  It uses Appscript, so it's a no-go in  
MacRuby.  I'm

now rewriting it to load the DB2 data into postgres.

BTW, can anyone recommend a book on Ruby idioms, frinstance: change  
all 'x'

in a string to 'y'?

Bob Schaaf


On Feb 8, 2009, at 5:28 PM, Tedd Fox wrote:


Awesome advice!!!  I actually "accidentally" did that last night :-)
Thanks!  I am learning Ruby and I am a Macintosh NOT but do not  
"get"
objective-C for some reason, so I am choosing MacRuby as my  
Speciality.  I

am glad MacRuby came along :-)

I like the faster prototyping ability (which is exactly what I  
need).


Any other advice for a newb?  A real newb?


On Feb 8, 2009, at 4:22 PM, Robert Schaaf wrote:


Hello Tedd,

This happened to me until I realized that I updated from the  
testing
branch, rather than the development branch.  My guess is that  
you've done

the same.

You need to go here 

and follow the directions at the top of the page.

Then you need to wait for documentation, and more frameworks  
mapped.


Then you need to wait for the ability to lay out your windows  
precisely,
in a Cocoa-compliant way.  (The sliders in the Layout View app  
are an

egregiously awful example!)
Or learn to integrate it with Interface Builder.

Also, MacRuby, which is wonderful beyond measure, will have to  
mature.

Without gems, life is not worth living.

Bob Schaaf


On Feb 8, 2009, at 7:05 AM, 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- 
cbdd6d06ece482e124516

Re: [MacRuby-devel] Ruby/SDL bindings with MacRuby (Cocoa?)

2009-02-14 Thread John Shea

Hi Timothy,

I have converted Tim Burks RubyRocks - a simple Asteroids game to  
MacRuby - with NSViews and another version to use OpenGL.

The OpenGL version has some ObjC code to get access to pixels.

They are at johmacshea.org - which bounces to my idisk while I am on  
holidays - in the MacRuby/Game Related.


In the Hillegas directory on the same site there is a MacRuby example  
that uses CoreAnimation - called Polynomials - I don't think its  
however appropriate to write action games in - or at least not  
initially as easy as other possibilities - though i would be happy to  
see someone prove me wrong - since in some ways it would be easier  
than OpenGL .


Let me know if you have any issues getting them running.
Cheers
John

On Feb 15, 2009, at 7:06 AM, Laurent Sansonetti wrote:


Timothy,

I don't think that the Ruby/SDL bindings can be used today inside  
MacRuby. The extensions mechanism still suffers from problems.


While I'm not a Quartz expert I am pretty sure you can replace Ruby/ 
SDL by pure Mac OS X APIs, with as Quartz but also CoreImage,  
CoreAudio, CoreAnimation, OpenGL (which can be called from MacRuby),  
etc. Now it depends if you want to write cross-platform code.


HTH,
Laurent

On Feb 14, 2009, at 9:35 PM, Timothy McDowell wrote:

Is it possible for me to use the Ruby/SDL bindings with MacRuby/ 
Cocoa? Also, can Quartz handle movement of sprites (gifs, pngs,  
jpgs?) and the like? Would Quartz be just fine for game development?


--
--Timothy.
___
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] Ruby/SDL bindings with MacRuby (Cocoa?)

2009-02-16 Thread John Shea
Timothy: I assume NVM - means never mind ;-). Let me know otherwise (I just
downloaded in fine on a friend's Mac).
>Speaking of games, let me repeat ...
Jordan:  I will do this at some stage, because I too think its an
interesting one (but not in the next couple of months) with the possibility
of using the tech for a non action oriented game. .. -  the animation in the
Polynomials example (macruby) - using CoreAnimation - is beautifully smooth,
with quite minimal setup.


On Mon, Feb 16, 2009 at 1:29 PM, Timothy McDowell wrote:

> NVM >_>
>
>
> On Sun, Feb 15, 2009 at 7:29 PM, Timothy McDowell wrote:
>
>> Can't download the files or even view them at your site/iDisk there...
>>
>> On Sun, Feb 15, 2009 at 11:06 AM, Jordan K. Hubbard wrote:
>>
>>>
>>> On Feb 14, 2009, at 11:37 PM, John Shea wrote:
>>>
>>> In the Hillegas directory on the same site there is a MacRuby example
>>> that uses CoreAnimation - called Polynomials - I don't think its however
>>> appropriate to write action games in - or at least not initially as easy as
>>> other possibilities - though i would be happy to see someone prove me wrong
>>> - since in some ways it would be easier than OpenGL .
>>>
>>>
>>> Speaking of games, let me repeat my suggestion that
>>> http://developer.apple.com/samplecode/GeekGameBoard/index.html 
>>> <http://developer.apple.com/samplecode/GeekGameBoard/index.html>would
>>> be a fine "conversion target" and an excellent jumping-off point for some
>>> games that might indeed be well-suited to being written in MacRuby.
>>>
>>> - Jordan
>>>
>>>
>>> ___
>>> MacRuby-devel mailing list
>>> [email protected]
>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>>
>>>
>>
>>
>> --
>> --Brains.
>>
>
>
>
> --
> --Brains.
>
> ___
> 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] 0.4 release

2009-02-18 Thread John Shea
Hi Laurent,
What sort of articles are you thinking of? I assume the blog's aim is to
attract new people.

I personally would not mind seeing an article on deploying an app to Leopard
without ruby/MacRuby installed.

I guess there will need to be a 0.4 article also (which i assume you are the
only one qualified to do).

I have the kernel of a simple tutorial on www.johnmacshea.org, about writing
a gui app communicating to a remote server (a vocab tester) - would that be
suitable? (i would need to clean and expand it)  I wont be able to do for
2-3 weeks however. The other stuff on that site are for people already
familiar with MacRuby so are probably not appropriate for the main blog.

Otherwise suggest something - and if its in my competence I am happy to do
it!
Cheers,
John

On Thu, Feb 19, 2009 at 8:10 AM, Laurent Sansonetti
wrote:

> Hi guys,
>
> I think that trunk has been under development for too long. It contains
> lots of fixes and improvements over 0.3, the current release, and we should
> push a 0.4 release out of the doors.
>
> I thought that we would be able to write a new IO subsystem for 0.4,
> despite the fact that this effort has started it seems that it won't be
> completed any time soon. I don't see the new IO subsystem rewrite as a
> blocker because trunk is already used by several projects.
>
> Thoughts? I would like to release trunk as 0.4 next week.
>
> On a related note, the blog is not very active at the moment.  Would
> someone be willing to contribute articles to it?
>
> Laurent
> ___
> 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] Starting a New Project tutorial

2009-03-16 Thread John Shea

I am not sure I understand fully what you have done ..

Make sure that you have something selected in the MainMenu.nib -  
otherwise the every panel in the inspector will be blank.


But this is what should happen:
- with the blue Object selected, and the Inspector open
- if you click in the object identity panel
- the class will be a grey NSObject
- click in this text field and the class name will disappear
- start typing in the name of your class - and it should appear -  
press return to make it stick.


If that does not help perhaps you could send the list a screen shot?

Cheers,
J

On Mar 16, 2009, at 13:58 , Frisco Del Rosario wrote:

I'm following the steps to Starting a New Project at http://www.macruby.org/trac/wiki/MacRubyTutorial 
, which says:


First, let's instantiate our class. In the Library pane, drag-and- 
drop an NSObject item to the main window. Then, make sure you  
selected it, and open the inspector pane (click on Window, then  
Document Info). In the Object Identity tab, select MyController as  
the object class.


But after dragging and dropping an NSObject into the MainMenu.nib  
window, Document Info shows nothing in the Object ID panel.


OS 10.5.6
Xcode 3.1.2
ruby 1.9.1p0
MacRuby 0.4

___
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] I want to help

2009-03-18 Thread John Shea
Hello Frisco,
one option for you is to become an expert in something MacRuby.

One area for example that could give you some good skills and could be good
for the MacRuby community (if you release the results) is the CoreAnimation
area, an area I was hoping I would have time for but will not.

So:
1. You could take a look at the example I translated on johnmacshea.org - in
the Hillegas examples - Polynomials.

2. Then you could translate Bill Dudney's CoreAnimation examples with these
screencasts :
http://www.pragprog.com/screencasts/v-bdcora/creating-a-compelling-user-interface-with-core-animation
(He also has a book - available as a pdf at the pragprogs - if you are
really keen do that as well).

You will probably need to buy the screencasts - and I actually have not
checked with the PragProgs whether they are happy to have MacRuby versions
of their Objective C code floating around.

I have done the macruby translations for the first two or three screencasts.

3. Then you could translate this:
http://cocoawithlove.com/2009/03/asteroids-style-game-in-coreanimation.html
I am actually not sure what the performance would be in MacRuby - in the
4th instalment in that series Matt suggests that CoreAnimation (in
ObjectiveC) can sometimes have performance issues with many layers.

4. Then for the final exam of your short course ;-) you could do what Jordan
Hubbard suggested and translate this
http://developer.apple.com/samplecode/GeekGameBoard/index.html.


If you are interested in following this path let me know and I will send you
what I have done in the Bill Dudney screencasts. Even if we aren't allowed
to release the macruby versions into the wild - you could learn from the
process and help you on the next steps.

Cheers,
J

On Wed, Mar 18, 2009 at 4:58 AM, Frisco Del Rosario
wrote:

> I am an old dog learning new tricks by reading. I remember that when I was
> a young dog, I learned better by doing.
>
> So I would like to help someone do something. I have experience writing
> unit tests and documentation, but would like to do anything.
> ___
> 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] Accessing bytes within NSData

2009-03-24 Thread John Shea

Did I miss the answer to this one?
I have a similar issue returning bytes, voids, GLfloats etc
J

On Mar 22, 2009, at 11:18 PM, Pete Yandell wrote:

I'd like to use something like Ruby's String#unpack to pull some  
info out of an NSData, but I'm stumped as to how to do it.


NSData.bytes returns a Pointer object, but trying to use [] to  
dereference it gives me:


	ArgumentError: can't convert C/Objective-C value `0x800059800' of  
type `?_?' to Ruby object


I've done a lot of digging around, reading of forum posts, playing  
(unsuccessfully) with BridgeSupport, etc., but it hasn't got me any  
closer. Any hints?


The broader context is that I'm trying to extract the TCP port  
number from an NSSocketPort. NSSocketPort's address method returns  
an NSData, which should contain a sockaddr_in, out of which I should  
be able to pull the port.


Thanks,

Pete Yandell
http://notahat.com/
___
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] # of developers

2009-03-30 Thread John Shea

Here is the blurb:
http://www.macruby.org/project.html

J
On Mar 30, 2009, at 16:53 , Joel Reymont wrote:


How many people are actively developing MacRuby apart from Laurent?

Thanks, Joel

---
http://tinyco.de
Mac, Lisp, OCaml




___
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] Accessing Obj-C InstVars from Ruby

2009-03-30 Thread John Shea
Hello Edward,

well since no one else has answered i will speculate a bit (it might
provoke someone wiser).

I assume that the Ruby and the Objective C class are magically married
together perhaps via some sort of proxy class - since you cant as far
as i know add to an objective C class more instance methods - and
inserting a compiled class into a ruby class must be also problematic
- anyway it seems complicated. So I assume that the ruby class is
actually still a separate class. I must admit i never tried to extend
a compiled object C class - and I surprised it works as well as it
does.

Given that, what about just adding getters and setters in the usual
way to the objective class manually or with properties (see
http://theocacao.com/document.page/510)?

Or just rewrite the whole class in Ruby?

Cheers,
J





On 3/30/09, Edward Hynes  wrote:
> Is there a way to access instance variables defined in an Objective-C
> class from a Ruby extension?  I'm porting some of Apple's example code
> to MacRuby as a learning experience and would like to do so
> incrementally.  Porting the code one class at a time works fine, but
> for some of the larger classes I'd like to port them a few methods at
> a time.  Here's an example of what's happening
>
>
> --- Example.h ---
>
> @interface Example : NSObject {
> NSString *instVarA;
> NSString *instVarB;
>  }
>
> - (NSString *)methodA;
> @end
>
>
> --- Example.m ---
>
> #import "Example.h"
>
> @implementation Example
>   - (id)init {
> if (self = [super init]) {
>   instVarA = @"instVarA";
>   instVarB = @"instVarB";
> }
> return self;
>   }
>
>   - (NSString *)methodA {
> return instVarA;
>   }
>
> @end
>
>
> --- Example.rb ---
>
> class Example
>   def methodB
> @instVarB
>   end
> end
>
>
> Then at runtime, when I execute the following...
>
> example = Example.alloc.init
> puts example.methodA.inspect
> puts example.methodB.inspect
>
>
> .. I get
>
> "instVarA"
> nil
>
>
> How do I access InsVarB from Ruby?
>
> Thanks,
> Ed
>
>
> ___
> 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] helping out

2009-03-30 Thread John Shea
Hi Matt,

you said:
> If you were thinking about helping out, be reassured, help is always welcome 
> ;)

I would happily spend some time on MacRuby, but I have no idea where to start.
I downloaded the experimental branch - was not really sure to go from
there but tried running some simple ruby code with the miniruby
executable - it hung so I assume I was doing something wrong.

Anyway I was wondering whether you could give me a quick run down on
how to start investigating learning and experimenting with the
experimental branch. Any links would be helpful. I would like to start
as simple as possible - but down the track one particular part that i
would be interested in is tracing the dispatch from bridgesupport
method to opengl function.

I can't really spend much time until after the Amsterdam conference however.

Speaking of which is it you that cannot make it? Pity if so - I was
looking fwd to your talk as I have some very flakey code which
interfaces with some traditional (ie non REST) webservices - I was
hoping for some (yet more) tips ;-).

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


Re: [MacRuby-devel] HotCocoa table_view and the doubleAction

2009-04-01 Thread John Shea

Hi Dave,

I am actually wrestling with a similar problem.

 I believe I have solved your problem, maybe you can solve mine ;-) ??

in the start method I placed:
  @my_table_view.setTarget(self)
  @my_table_view.setDoubleAction(:double)


and then later on a method:

  def double
NSLog ("double")
  end


My issue is also delegating table updates to certain methods.

I noticed that tableview.setDelegate(self) did not do anything - and  
then I assumed that the TableDataSource is actually handling the  
delegate  - confirmed when I changed the numberOfRowsInTableView  
method to return the value 1.


But then I assume that I am not supposed to add my own tableView(tv,  
setObjectValue:anObject, forTableColumn:col, row:row) method to the  
HotCocoa TableDataSource file?


What happens if I have two tables in the one application with  
different delegated behaviour?


Am I supposed to get funky and add the different versions of the  
tableView methods to the data instance itself?
Is there a way to override the delegate dispatch to actually go a  
local class?


or do I setActions like in the double clicked example above?

Cheers and thanks,
J







On Apr 1, 2009, at 11:33 , Dave Baldwin wrote:

I am having some difficulty on getting the double click action to  
work with a table view.  I have code along the lines of:



@tableView = table_view(
:columns => [column(:id => :item, :title 
=> '')],
:data => @filteredData
)


@tableView.doubleAction = 'doubleClickInRow:'

def @tableView.doubleClickInRow (sender)
NSLog "in double click"
end

When I run and double click on a row in the table I get:

*** -[RBAnonymous132 doubleClickInRow:]: unrecognized selector sent  
to instance 0x8005d1c40



Does anyone know how to get this to work?

Thanks,

Dave.
___
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] HotCocoa table_view and the doubleAction

2009-04-01 Thread John Shea

Hi Dave,

thanks for your answer.

On Apr 1, 2009, at 14:39 , Dave Baldwin wrote:


I haven't had any problems using delegate methods. For example I do:

@tableView.delegate = self

and define a delegate method:

def tableView (table, shouldEditTableColumn: c, row: r)
false
end


Thats the first thing I tried - but for the tableView(table,  
setObjectValue .. method which was not delegated to.


Unfortunately as it was the first one i tried (because i wanted to  
edit table fields) -  that sent me on a wild goose chase trying to  
figure out why the delegate was not working as it was in all of my non- 
hotcocoa code.


So thanks for pointing out that some of them are actually delegated to.

For me:


  #works
  def controlTextDidChange(notification)
  NSLog("controlTextDidChange #{notification.object}")
  NSLog(@mv_table_view.selectedRow.to_s)
  end

  #works
  def tableView(tv, willDisplayCell:cell, forTableColumn:col,  
row:the_row)

   NSLog("willDisplayCell")
  end

  #works
  def tableViewSelectionDidChange(notification)
NSLog("tableViewSelectionDidChange")
  end

#is not delegated to
  def tableView(tv, setObjectValue:anObject, forTableColumn:col,  
row:row)

NSLog("tableView setObject")
#edit data here
  end

#is not delegated to
  def numberOfRowsInTableView(tv)
NSLog("numberOfRowsInTableView")
0 #test 0
  end

#is not delegated to
  def tableView(tv, objectValueForTableColumn:col, row:row)
NSLog("objectValueForTableColumn")
val = "richard"
  end


I could probably do a work around with controlTextDidChange - but it  
seems a bit dodgy.
Or another option would be to edit not within the table, but in  
another form.


I suppose there is some simple explanation - but I am missing it for  
the moment.


Cheers,
J






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


Re: [MacRuby-devel] HotCocoa table_view and the doubleAction

2009-04-01 Thread John Shea

Thanks Brian!

that cleared up all the remaining puzzles !

I must admit i just assumed that the data source and delegate were  
married together in some way in hotcocoa - now that you have given me  
a much better background it all now makes sense.


And thanks for the link.

Cheers,
John


On Apr 1, 2009, at 8:07 PM, Brian Chapados wrote:


You might have already figured this out, but in case it helps...

Be careful not to confuse the TableView delegate with the DataSource  
delegate.

Check out the TableView programming guide:
http://developer.apple.com/documentation/Cocoa/Conceptual/TableView/TableView.html

You can use two different sets of delegate messages to customize an
NSTableView.  The datasource delegate methods get called in order to
populate the table with data. The TableView delegate methods get
called in response to user-generated events.

The DataSource informal protocol:
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Protocols/NSTableDataSource_Protocol/Reference/Reference.html#/ 
/apple_ref/occ/cat/NSTableDataSource


delegate methods specific for a TableView:
http://developer.apple.com/documentation/Cocoa/Conceptual/TableView/Tasks/UsingTableDelegate.html#/ 
/apple_ref/doc/uid/2116-CJBDHFIC


Your tableview delegate can also respond to delegate messages for
NSControl and NSView (its superclasses).

In your list below,

#is not delegated to
 def tableView(tv, setObjectValue:anObject, forTableColumn:col,  
row:row)

   NSLog("tableView setObject")
   #edit data here
 end
#is not delegated to
 def numberOfRowsInTableView(tv)
   NSLog("numberOfRowsInTableView")
   0 #test 0
 end
#is not delegated to
 def tableView(tv, objectValueForTableColumn:col, row:row)
   NSLog("objectValueForTableColumn")
   val = "richard"
 end


These methods are sent to the 'dataSource' delegate, not the
'delegate' (view delegate).  In order for your dataSource delegate
methods to be called, you need to either:

1. Define the methods in a separate class, and assign an instance of
that class as:
@tableView.dataSource = myDataSource

2. Define the methods in your TableView Controller class, set the
dataSource delegate to self:
@tableView.dataSource = self

You _must_ set the tableView delegate in order to receive the
messages, even if you have everything in one class and you just want
to set them to 'self'.

For simple cases, you can implement both the 'dataSource' and view
'delegate' classes in your TableView controller and set both delegates
to self.  For an example of this, see the FlickrDemo example app in
macruby-examples dir.

Also, since it was mentioned, you should be able to leave the 'target'
property unset (or set it to nil).  In cocoa, nil targeted actions do
_not_ go into the void.  Instead, they sent are passed along the
responder chain so that the next appropriate control can handle the
message. This is useful for when you want to the same action to be
performed as a result of different inputs (i.e. menu, button or click
in row, ect..).  You can just define the action methods in a class
that is part of the responder chain and send a nil targeted actions
from your controls.

There is must-listen Mac-Developer Network podcast interview with
Aaron Hillegass on the Responder Chain:
http://www.mac-developer-network.com/shows/podcasts/lnc/lnc009/

Brian

2009/4/1 John Shea :

Hi Dave,
thanks for your answer.

On Apr 1, 2009, at 14:39 , Dave Baldwin wrote:

I haven't had any problems using delegate methods. For example I do:
@tableView.delegate = self
and define a delegate method:
def tableView (table, shouldEditTableColumn: c, row: r)
false
end

Thats the first thing I tried - but for the tableView(table,  
setObjectValue

.. method which was not delegated to.
Unfortunately as it was the first one i tried (because i wanted to  
edit
table fields) -  that sent me on a wild goose chase trying to  
figure out why
the delegate was not working as it was in all of my non-hotcocoa  
code.
So thanks for pointing out that some of them are actually delegated  
to.

For me:

  #works
  def controlTextDidChange(notification)
  NSLog("controlTextDidChange #{notification.object}")
  NSLog(@mv_table_view.selectedRow.to_s)
  end

  #works
  def tableView(tv, willDisplayCell:cell, forTableColumn:col,  
row:the_row)

   NSLog("willDisplayCell")
  end
  #works
  def tableViewSelectionDidChange(notification)
NSLog("tableViewSelectionDidChange")
  end
#is not delegated to
  def tableView(tv, setObjectValue:anObject, forTableColumn:col,  
row:row)

NSLog("tableView setObject")
#edit data here
  end
#is not delegated to
  def numberOfRowsInTableView(tv)
NSLog("numberOfRowsInTableView")
0 #test 0
  end
#is not delegated to
  def tableView(tv, objectValueForTableColumn:col, row:row)
NSLog("objectValueForTableColum

Re: [MacRuby-devel] Obj-C translation

2009-04-02 Thread John Shea
Hi there,


if you look about a quarter of the way down this page ( the introductory
tutorial) http://www.macruby.org/documentation/tutorial.html

you will see it all explained.


In this case:


- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)proposedFrame


could become:


windowShouldZoom(window,  toFrame:proposedFrame)


there are other ways too, check out the page above.


Cheers,

J

On Fri, Apr 3, 2009 at 5:59 AM, Frisco Del Rosario wrote:

>
> What's the MacRuby style for this Obj-C ?
>
> - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)proposedFrame
>
> From
> http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/windowShouldZoom:toFrame
> :
> How can a method be named Blah(arg) space blah(arg)?
> ___
> 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] Obj-C translation

2009-04-03 Thread John Shea
I guess the another thing to check is that you have actually set your  
class (with the code below) to be the delegate in IB?



On Apr 3, 2009, at 14:56 , Brad Wilson wrote:


Haha I am out of ideas sorry Frisco. Good luck with it!

On 03/04/2009, at 10:25 PM, Frisco Del Rosario wrote:


Brad Wilson:
> This is untested, but  I'd suggest trying:
> def webView(sender, didReceiveTitle:title, forFrame:frame)
>sender.window.setTitle(title)
> end

> Does that sound right to anybody else?
Eloy Duran:
> Yep that's correct.
Though Brad's suggestion did not result in the delegate method  
being triggered, and neither did the change setTitle:title, my  
enthusiasm is unflagging.



___
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] Unit testing in Xcode

2009-04-04 Thread John Shea
Brian Marick has a good chapter on testing in his "RubyCocoa, bringing  
some love. "  using standard ruby testing methodologies. You can  
get this as a pdf book (its not out in print yet)


(I am in no way affiliated to Brian, Aaron and the other Cocoa/Ruby  
authors i mention on this list - my apologies if it seems so).




On Apr 4, 2009, at 11:39 AM, Frisco Del Rosario wrote:

Is unit testing in Xcode necessarily as cumbersome as it seems to be  
described in http://developer.apple.com/documentation/developertools/Conceptual/UnitTesting/Articles/CreatingTests.html 
 ?


Xcode is making me miss the days I could just append a TestCase  
instance with TextMate and hit command-r.


___
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] Mixing Objective-C and Ruby classes

2009-04-17 Thread John Shea

Hello Victor,

I see that there is not much action on the list at the moment - so I  
will reply - the heavyweights do eventually drop by - but they are  
very busy so it is a bit sporadic (unless its just my gmail playing up  
again).


I haven't actually tried 2 and 3 on your list since I am trying to  
obviate the need to actually write anything in Objective C. I guess if  
you have Obj C code already then you might want to call ruby rather  
than the other way around, so I will leave those questions for others  
and answer the simple one.


For number 1:
If you are using Xcode it all seems to work magically, and I am not  
sure why you are having problems.


If I want to call some Obj C code from a ruby class - i first create  
an obj c class (eg MyClass) the normal way in Xcode (with .m and .h  
classes becoming part of the project), write the obj c code, and then  
any ruby code can magically use that class - eg with:


MyClass.my_class_method

or

a = MyClass.new
a.my_instance_method

or
a =MyClass.init.alloc
a.my_instance_method

if you want to access state in the obj c class - there was a thread on  
that recently (subject Accessing Obj-C InstVars from Ruby) - but I use  
getters and setters in the Obj C code.


Hope that helps,
John


On Apr 16, 2009, at 13:23 , [email protected] wrote:


Hi,

 I'm new both to this list and to MacRuby. Let this message serve as  
an introduction.


 I have some questions that have not seen answered either in the  
docs or in the list archives. I have been known to miss things  
before, so please kindly point  me in the right direction if this is  
documented somewhere.


I have seen the embedding sample but I stil can't figure out how I  
can pull out the following:


1. Mix Obj-C and Ruby Classes: ie, from Ruby be able to extend or  
use Obj-C classes that are lying around in my project. How do I  
"require" them? When I try to use them, ruby doesn't seem to  
recognize them (specifically, it recognizes the classes but not  
their methods)
2. The same question, but the other way around: how can I use or  
extend a class declared in Ruby from Obj-C? The only thing that I  
can come up with is to declare them with @class, but it didn't work  
(or I didn't do it properly)
3. If I were to call arbitrary scripts as in the embedding sample,  
how can I pre-initialize ruby objects so that they are available in  
the environment? I.e, if I allow the user to extend my app by  
running their ruby code, how can I make my objects available to him?  
And also, how could I prevent certain objects from being available  
to him, so that he doesn't break anything?



TIA,

victor ___
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] strings to yaml

2009-04-17 Thread John Shea

Hello everyone,

I notice that NSMutableString nicely turns into a plain string when  
you #to_yaml it.


Thats great since plays nicely with other ruby code.

NSString however becomes "!str:NSString"   -   is that by  
design?


It would not matter to me except that #stringValue from NSTextFields  
returns NSString - which i must first copy to a NSMutableString before  
I #to_yaml it.


Just wondering if there is a more elegant way.

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


Re: [MacRuby-devel] strings to yaml

2009-04-17 Thread John Shea

Hi Eloy,

I was doing:

"#{field.stringValue}".to_yaml

which in 6 months time i will be scratching my head wondering why - so  
your suggestions are very helpful - thanks!


Cheers,
J

On Apr 17, 2009, at 15:31 , Eloy Duran wrote:


Hey John,

I think we'll need to move the to_yaml definition for String into  
NSString in the MacRuby case.
I tried to do that as an example [1], but it seems that NSString  
completely breaks after opening the class, but this is probably just  
a bug in 0.4:


"--- foo\n"
"--- !str:NSString foo\n"
untitled:28:in `': undefined method `stringWithString' for  
NSString:Class (NoMethodError)


So for now a workaround like the following might do:

require "yaml"

def String(str)
 NSMutableString.stringWithString(str)
end

p NSMutableString.stringWithString('foo').to_yaml # => "--- foo\n"
p String(NSString.stringWithString('foo')).to_yaml # => "--- foo\n"

Cheers,
Eloy

[1]:
require "yaml"

p NSMutableString.stringWithString('foo').to_yaml # => "--- foo\n"
p NSString.stringWithString('foo').to_yaml # => "--- !str:NSString  
foo\n"


# YAML String definition
class NSString
 def to_yaml( opts = {} )
   YAML::quick_emit( is_complex_yaml? ? object_id : nil, opts ) do | 
out|

 if is_binary_data?
   out.scalar( "tag:yaml.org,2002:binary",  
[self].pack("m"), :literal )

 elsif to_yaml_properties.empty?
   out.scalar( taguri, self, self =~ /^:/ ? :quote2 :  
to_yaml_style )

 else
   out.map( taguri, to_yaml_style ) do |map|
 map.add( 'str', "#{self}" )
 to_yaml_properties.each do |m|
   map.add( m, instance_variable_get( m ) )
 end
   end
 end
   end
 end
end

p NSString.stringWithString('foo').to_yaml # => "--- !str:NSString  
foo\n"


On Apr 17, 2009, at 3:05 PM, John Shea wrote:


Hello everyone,

I notice that NSMutableString nicely turns into a plain string when  
you #to_yaml it.


Thats great since plays nicely with other ruby code.

NSString however becomes "!str:NSString"   -   is that by  
design?


It would not matter to me except that #stringValue from  
NSTextFields returns NSString - which i must first copy to a  
NSMutableString before I #to_yaml it.


Just wondering if there is a more elegant way.

Cheers,
John
___
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] OpenGL Bus Error

2009-05-04 Thread John Shea

Hi Timothy,

maybe you have figured it all out by now - but when doing openGL stuff  
it is usually in the context (literally and metaphorically) of an  
NSOpenGLView, you also have to overwrite the initWithFrame method and  
a few other methods in this class. Within the init method you set up  
the pixel depth, buffer type etc, and you have to make the  
openGLContext the current context.


I can send you a small Xcode sample if you like.

Cheers,
J


On May 4, 2009, at 11:36 PM, Timothy McDowell wrote:


I was using the 'macirb' and this is what I got:

I had entered this:
dawnmcds-powerbook-g4-12:~ Tim$ macirb
irb(main):001:0> framework 'cocoa'
=> true
irb(main):002:0> framework 'opengl'
=> true
irb(main):003:0> a = NSSize.new
=> #
irb(main):004:0> a
=> #
irb(main):005:0> a.width
=> 0.0
irb(main):007:0> a.width = 640
=> 640
irb(main):008:0> a.height = 480
=> 480
irb(main):009:0> a
=> #
irb(main):010:0> glMatrixMode(GL_PROJECTION)

and then the glMatrixMode call got me this bus error:

(irb):10: [BUG] Bus Error
MacRuby version 0.4 (ruby 1.9.1) [universal-darwin9.0, ppc]

-- stack frame 
 (0x30040): 0004
0001 (0x30044): 
0002 (0x30048): 0004
0003 (0x3004c): 
0004 (0x30050): 0004
0005 (0x30054): 
0006 (0x30058): 00571940
0007 (0x3005c): 010cb370
0008 (0x30060): 0128e100
0009 (0x30064): 0004
0010 (0x30068): 01411e60
0011 (0x3006c): 0004
0012 (0x30070): 0056de80
0013 (0x30074): 0004
0014 (0x30078): 000aff74
0015 (0x3007c): 0004
0016 (0x30080): 01411e8c
0017 (0x30084): 0128e100
0018 (0x30088): 0004
0019 (0x3008c): 01411f60
0020 (0x30090): 01069660
0021 (0x30094): 0004
0022 (0x30098): 000afe94
0023 (0x3009c): 0004
0024 (0x300a0): 0057a6f0
0025 (0x300a4): 0004
0026 (0x300a8): 000afe5c
0027 (0x300ac): 0004
0028 (0x300b0): 00030098 (= 22)
0029 (0x300b4): 0004
0030 (0x300b8): 0004
0031 (0x300bc): 000afdb4
0032 (0x300c0): 0144aab0
0033 (0x300c4): 0004
0034 (0x300c8): 000300b0 (= 28)
0035 (0x300cc): 01438510
0036 (0x300d0): 0015
0037 (0x300d4): 0004
0038 (0x300d8): 01262e44
0039 (0x300dc): 0004
0040 (0x300e0): 0056e740
0041 (0x300e4): 0056e110
0042 (0x300e8): 0004
0043 (0x300ec): 000afcd4
0044 (0x300f0): 0004
0045 (0x300f4): 0004
0046 (0x300f8): 0004
0047 (0x300fc): 0004
0048 (0x30100): 0004
0049 (0x30104): 0004
0050 (0x30108): 0004
0051 (0x3010c): 000300d8 (= 38)
0052 (0x30110): 0128dc30
0053 (0x30114): 01438510
0054 (0x30118): 0015
0055 (0x3011c): 0004
0056 (0x30120): 
0057 (0x30124): 0004
0058 (0x30128): 0128bf20
0059 (0x3012c): 0128dc30
0060 (0x30130): 01438510
0061 (0x30134): 0127c220
0062 (0x30138): 0015
0063 (0x3013c): 0004
0064 (0x30140): 
0065 (0x30144): 0004
0066 (0x30148): 01438510
0067 (0x3014c): 012b5910
0068 (0x30150): 0127c220
0069 (0x30154): 0015
0070 (0x30158): 0004
0071 (0x3015c): 
0072 (0x30160): 0004
0073 (0x30164): 
0074 (0x30168): 0004
0075 (0x3016c): 0144b180
0076 (0x30170): 0004
0077 (0x30174): 2e03
0078 (0x30178): 0004
0079 (0x3017c):  <- lfp <- dfp
-- control frame --
c:0024 p: s:0080 b:0080 l:79 d:79 CFUNC  :glMatrixMode
c:0023 p:0014 s:0076 b:0076 l:000214 d:001f64 EVAL   (irb):10
c:0022 p: s:0074 b:0074 l:73 d:73 FINISH :empty?
c:0021 p: s:0072 b:0072 l:71 d:71 CFUNC  :eval
c:0020 p:0023 s:0065 b:0065 l:64 d:64 METHOD /Library/ 
Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/irb/ 
workspace.rb:80
c:0019 p:0025 s:0058 b:0057 l:56 d:56 METHOD /Library/ 
Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/irb/ 
context.rb:218
c:0018 p:0024 s:0052 b:0052 l:0024d4 d:51 BLOCK  /Library/ 
Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/irb.rb: 
149
c:0017 p:0025 s:0044 b:0044 l:43 d:43 METHOD /Library/ 
Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/irb.rb: 
263
c:0016 p:0009 s:0039 b:0039 l:0024d4 d:38 BLOCK  /Library/ 
Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/irb.rb: 
146
c:0015 p:0110 s:0035 b:0035 l:22 d:34 BLOCK  /Library/ 
Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/irb/ 
ruby-lex.rb:244

c:0014 p: s:0034 b:0034 l:33 d:33 FINISH :block_given?
c:0013 p: s:0032 b:0032 l:31 d:31 CFUNC  :loop
c:0012 p:0007 s:0029 b:0029 l:22 d:28 BLOCK  /Library/ 
Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/irb/ 
ruby-lex.rb:230

c:0011 p: s:0029 b:0029 l:28 d:28 FINISH :each
c:0010 p: s:0027 b:0027 l:26 d:26 CFUNC  :catch
c:0009 p:0017 s:0023 b:0023 l:22 d:22 METHOD /Library/ 
Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/irb/ 
ruby-lex.rb:229
c:0008 p:0034 s:0020 b:0020 l:0024d4 d:0024d4 METHOD /Library/ 
Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/irb.rb: 
145
c:0007 p:0009 s:0017 b:0017 l:00130

Re: [MacRuby-devel] Problem with MacGem install

2009-05-25 Thread John Shea
I have translated and created some examples using opengl with MacRuby  
here:


http://www.johnmacshea.org/examples/GameRelated/

The directory Mine/ has examples which although longer - are "cleaner"

HTH,
John


On May 25, 2009, at 20:59 , Matt Aimonetti wrote:

There is problem with macgem not installing gems properly. You can  
try to unpack your gem and require it manually (recommended since  
you don't want to force your users to install gems).


However ruby-opengl uses C extensions which will probably not be  
MacRuby 0.4 compatible. The good news tho, is that you can do all  
your opengl stuff using the cocoa API :)


- Matt

On Mon, May 25, 2009 at 10:23 AM, Jonathan Waddilove > wrote:
Hi, I'm just starting to use MacRuby and I would like to be able to  
use OpenGL.  So far I have been unable to install the GEM.


I have just checked out the current MacRuby trunk (Mon 25 May) and  
after building it I get the following error:


sudo macgem install ruby-opengl
 Password:
 macruby(37134,0x1037a5000) malloc: free_garbage: garbage ptr =  
0x800031ca0, has non-zero refcount = 1

 ERROR:  While executing gem ... (RangeError)
   bignum too big to convert into `unsigned long long'

Umm, is there a problem with the MacGem tool in the current drop or  
have I made a silly user error.


Many thanks, Jonathan

___
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] MacRuby Document-based Application template in XCode?

2009-06-17 Thread John Shea

Hi Paul,

I think when I first did it I just copied what an objective C document  
based application did.


The thing that was not so obvious to me at the time was putting the  
appropriate text in the Info.plist file.


I have a few document based application examples translated from  
Hillegas at johnmacshea.org (it points to an idisk currently while I  
play with SL server) - go to MacRuby/Hillegass and have a look at the  
"CH27 Printing" example (press the download arrow to download the zip).


Hope that helps,
Cheers,
John



On Jun 17, 2009, at 8:59 , Paul Howson wrote:


Hi,

When using Objective-C, XCode provides you with a template for a  
"Cocoa Document-based Application".


For MacRuby we so far have in XCode only "MacRuby Application" and  
"MacRuby Core Data Application".


Would it work to take a new MacRuby Application and copy across the  
relevant bits from a new Cocoa Document-based Application in order  
to make a MacRuby Document-based Application?


Is it that simple, or are there other gotchas I need to know about?

Paul Howson
Queensland Australia
___
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] DRb and macruby

2009-06-22 Thread John Shea

Hello all,

anyone using DRb and macruby?

I know next to nothing about DRb but its giving me some crashes in  
macirb that it is not in irb, for setting variables on the server side.


For example (I have coloured responses so its easier to see the  
difference between input and output):


with the simple server below running:
require 'drb'

class TestServer
  attr_accessor :var_a, :var_b
end

aServerObject = TestServer.new
DRb.start_service('druby://localhost:9000', aServerObject)
DRb.thread.join


#irb in a terminal:

dev:~ johnshea$ irb
>> require 'drb'
=> true
>>
?> DRb.start_service
=> #@protocol=#@argc_limit=256, @load_limit=26214400>, @socket=#,  
@uri="druby://dev:50029", @acl=nil,  
@config 
= 
{:tcp_acl 
= 
> 
nil 
, :argc_limit 
= 
> 
256 
, :safe_level 
=>0, :load_limit=>26214400, :verbose=>false, :idconv=>#0x5d1060>}>, @thread=#,  
@idconv=#, @uri="druby://dev:50029",  
@front=nil, @grp=#,  
@config 
= 
{:tcp_acl 
= 
> 
nil 
, :argc_limit 
= 
> 
256 
, :safe_level 
=>0, :load_limit=>26214400, :verbose=>false, :idconv=>#0x5d1060>}>

>> obj = DRbObject.new(nil, 'druby://localhost:9000')
=> #
>> obj.var_a = 45
=> 45


#so far so good, now irb in another terminal:

dev:~ johnshea$ irb
>> require 'drb'
=> true
>>
?> DRb.start_service
=> #- same as above-->

>> obj = DRbObject.new(nil, 'druby://localhost:9000')
=> #
>> p obj.var_a
45
=> nil
>> obj.var_b = 45
=> 45

#yep thats fine, now another terminal

dev:~ johnshea$ irb
>> require 'drb'
=> true
>>
?> DRb.start_service
=> #- same as above-->

>> obj = DRbObject.new(nil, 'druby://localhost:9000')
=> #
>> obj.var_b = 100
=> 100

#all good, now for macirb terminal:

dev:~ johnshea$ macirb
>> require 'drb'
=> true
>>
?> DRb.start_service
=> ##-@config 
= 
{:tcp_acl 
= 
> 
nil 
, :load_limit=>26214400, :argc_limit=>256, :idconv=>#0x8007e9020>, :verbose=>false, :safe_level=>0}, @protocol=##- 
@socket=#,  
@config 
= 
{:tcp_acl 
= 
> 
nil 
, :load_limit=>26214400, :argc_limit=>256, :idconv=>#0x8007e9020 
> 
, :verbose 
=>false, :tcp_port=>50042, :tcp_original_host=>"", :safe_level=>0},  
@acl=nil, @msg=##-@argc_limit=256>>, @uri="druby://dev:50042", @front=nil,  
@idconv=#, @safe_level=0,  
@grp=#, @thread=#>

>> obj = DRbObject.new(nil, 'druby://localhost:9000')
=> ##-@ref=nil>

>> p obj.var_b
100
=> 100
>> obj.var_b = 99
/Library/Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/ 
drb/drb.rb:961: [BUG] destination 0x7fff5fbf7308 isn't in the auto zone

MacRuby version 0.4 (ruby 1.9.1) [universal-darwin9.5, x86_64]
-- stack frame 
 (0xc0860): 0004

--snip-- see the rest of the crash below

the crash log suggests that this is the problem line in drb.rb which is:
if IO.select([...@socket], nil, nil, 0)

#oops go back to a previous irb session
>> p obj.var_b
100
=> nil
>> obj.var_b = 99
=> 99
#hmm that works fine.


anyone got any ideas?

Cheers,
John

the crash:

/Library/Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/ 
drb/drb.rb:961: [BUG] destination 0x7fff5fbf7308 isn't in the auto zone

MacRuby version 0.4 (ruby 1.9.1) [universal-darwin9.5, x86_64]
-- stack frame 
 (0xc0860): 0004
0001 (0xc0868): 
0002 (0xc0870): 0004
0003 (0xc0878): 
0004 (0xc0880): 0004
0005 (0xc0888): 
0006 (0xc0890): 10039c630
0007 (0xc0898): 8003af520
0008 (0xc08a0): 8006883e0
0009 (0xc08a8): 0004
0010 (0xc08b0): 80078abe0
0011 (0xc08b8): 0004
0012 (0xc08c0): 100397b90
0013 (0xc08c8): 0004
0014 (0xc08d0): c080ffec8
0015 (0xc08d8): 0004
0016 (0xc08e0): 80078ac38
0017 (0xc08e8): 8006883e0
0018 (0xc08f0): 0004
0019 (0xc08f8): 80078ada0
0020 (0xc08000100): 800636380
0021 (0xc08000108): 0004
0022 (0xc08000110): c080ffd08
0023 (0xc08000118): 0004
0024 (0xc08000120): 1003a7dd0
0025 (0xc08000128): 0004
0026 (0xc08000130): c080ffc98
0027 (0xc08000138): 0004
0028 (0xc08000140): c08000110 (= 22)
0029 (0xc08000148): 0004
0030 (0xc08000150): 0004
0031 (0xc08000158): c080ffb48
0032 (0xc08000160): 800764fc0
0033 (0xc08000168): 0004
0034 (0xc08000170): c08000140 (= 28)
0035 (0xc08000178): 8005fb760
0036 (0xc08000180): 000d
0037 (0xc08000188): 0004
0038 (0xc08000190): 80078ade8
0039 (0xc08000198): 0004
0040 (0xc080001a0): 1003986e0
0041 (0xc080001a8): 100397ef0
0042 (0xc080001b0): 0004
0043 (0xc080001b8): c080ff988
0044 (0xc080001c0): 0004
0045 (0xc080001c8): 0004
0046 (0xc080001d0): 0004
0047 (0xc080001d8): 0004
0048 (0xc080001e0): 0004
0049 (0xc080001e8): 0004
0050 (0xc080001f0): 0004
0051 (0xc080001f8): c08000190 (= 38)
0052 (0xc08000200): 800670940
0053 (0xc08000208): 8005fb760
0054 (0xc08000210): 000d
0055 (0xc08000218): 0004
0056 (0xc08000220): 
0057 (0xc08000228): 0004
0058 (0xc08000230): 800670980
0059 (0xc08000238): 800670940
0060 (0xc08000240): 8005fb760
0061 (0xc08000248): 80074a820
0062 (0xc080

Re: [MacRuby-devel] Checkbox state

2009-07-08 Thread John Shea

Hi Marinus / Rien,

I just did a quick test, given a nib with window and a controller ruby  
file.


1. I dragged a checkbox NSButton onto the window
2. i created an attr_accessor :check in my controller
3. I created a method called test_check in my controller:

  def test_check(sender)
p @check.state
  end

4. I linked @check and the test_check method to the checkbox

And when i click on an off the checkbox the state toggles between 0  
and 1.


So I do not think it is an issue MacRuby - could you try something  
simple like the above?


How were you polling the check box state? That is: which method is  
status = @myCheckbox.state in?

Perhaps this method is not being called.

Cheers,
John


On Jul 8, 2009, at 15:06 , Marinus van der Lugt wrote:


Hi All,

First post, so a little bit about me: I am a SW engineer and have  
been one
for over 20 years, increadible as that may sound. I have programmed  
on the

Mac before in Ada95, Obj-C and Java (but I have had a pause of about 5
years from the Mac). Now that MacRuby seems to gain some foothold  
I'd like

to get back to the mac and make the jump from Obj-C to MacRuby.

I work in Xcode, and have just started a new MacRuby Core-Data  
Application.


The first goings look good, but in implementing my first window  
controller

I ran into a (little?) problem: I cannot get the state of a checkbox:

status = @myCheckbox.state

always returns a Fixnum with value 0. regardless of the visual
representation of the checkbox (i.e. selected or not)

The checkbox should be mapped correctly because:

myTitle = @myCheckbox.title

does indeed give me the title I set in the IB.
I checked the archives but did not find any discussions about this.
There was something about checkboxes and hotcocoa, but I do not use  
hotcocoa.


The best solution would be a simple stupid mistake on my part :-)

Any takers?

Regards,
Rien.

___
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] macruby on iphone (again) - options and way forward

2009-10-11 Thread John Shea

Hello everyone.

So I think this topic is going to rear its ugly/pretty head until a  
solution becomes available, and I myself would really like to be able  
to use macruby code on the iphone.


So I have put down my naive thoughts as to what are the issues.

I am a complete novice when it comes to GC, so I am sorry if this is  
all obvious or erroneous - but the important part is the discussion -  
which i hope many of you will add to.


Anyway it could be that I don't know enough about the subject to make  
sense of it. But a way to perhaps getting more people to work on  
getting macruby on the phone could be:


1. Describe the current GC situation on the mac & macruby in terms of  
architecture.
2. Describe an appropriate architecture for how GC would work on the  
iphone, how the programmer interacts with it in coding or compiling.
3. Describe the various parts of work that have to be done to to  
implement 2.
4. Make some suggestions of similar coding efforts or current code  
files or other references that people can use/copy to build a proof of  
principle


The following are my versions of 1 and 2:

Point 1:
My assumption is that currently macruby hooks into objective c's GC -  
autozone (this one ? http://www.opensource.apple.com/source/autozone/autozone-77.1/) 
 via ruby's ObjectSpace.


Point 2:
The iphone does not have GC so therefore in order to run macruby  
something needs to collect the garbage.


My other assumption is that you cannot run interpreted code on the  
iphone (or iphone simulator) so when developing for iphone the ruby  
code would need to be compiled during the build phase.


So I can think of two ways to do collect the garbage.

Firstly port autozone to the iphone - integrate macruby more or less  
as now - include it as a framework or something.

However,
  - i am concerned that the separate autozone thread(s) may not play  
well with the iphone processor
  - in addition the threads need to be interruptible, when phone  
calls come in or the home button is pressed - i can imagine including  
the autozone controller in the responder chain (in order to receive  
the shutdown command) would not be trivial.


I am wondering if the above complexity is why Laurent always refers to  
"emulating" autozone rather than including it or porting it.


The other option i can think of is in the build phase insert the  
necessary retains, releases and autoreleases into the code. By either:


	i) the developer including the calls manually, which are then  
compiled/translated to the appropriate C/ObjC commands. (I have gone  
off this idea a bit because the code would be hard to test in  
isolation (unless there were special compiler codes normally ignored  
by the ruby interpreter), and would make it hard to drop in any nice  
ruby code/libraries, and later on hard to fix code if an official GC  
ever arrives).


	ii) have a script which traverses the ruby code - and adds dealloc  
methods for instance methods, adds releases to scope bound variables  
etc, etc.
(I like this option the best, though i have little idea how to  
implement)


So do you all think i have described the situation properly?

If so perhaps someone (more knowledgeable) could provide some hints to  
points 3 and 4 above?


Or if i haven't described the situation properly then the whole stack  
of points 1-4 would (I think) help us move forward - and help people  
contribute to a solution.


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


Re: [MacRuby-devel] NSTimer

2009-10-11 Thread John Shea

Hi Bob,

(you are going to kick yourself) you have misplaced the colon between  
target and self  - there is a comma there, and the colon has been  
placed in front of "target", so the method is not being recognised.


eg:
@synchro_timer =  
NSTimer.scheduledTimerWithTimeInterval(TIME_INTERVAL, target:self,  
selector:"synchronise_with_server:", userInfo:nil, repeats:true)



as for threads - maybe someone else could chime in with a preference -  
but I do it the Cocoa way (eg http Connection delegates or timers) -  
but for data crunching using all cores I will use something like  
Laurent's barber shop code: http://www.macruby.org/blog/2009/10/07/macruby05b1.html 
.



J

On Oct 11, 2009, at 6:19 PM, Robert Rice wrote:


Congratulations MacRuby Development Team:

My application almost runs now in MacRuby.

Is NSTimer class supported in MacRuby?

I was doing background processing using NSTimer as follows:

@timer = NSTimer.scheduledTimerWithTimeInterval( 5.0, :target,  
self, :selector, :periodicUpdate, :userInfo, nil, :repeats, true )


but this now gives me the error:

undefined method `scheduledTimerWithTimeInterval' for NSTimer:Class  
(NoMethodError)


Do you have a preferred method for doing backgound tasks in MacRuby  
- perhaps separate threads?


Thanks,
Bob Rice

___
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] Translating Obj-C to MacRuby

2009-10-14 Thread John Shea

Hi Bernd,

YES and NO in ObjC are translated to true and false in MacRuby.

so you were probably after:

 NSNumber.numberWithBool(false)

(I am curious as to how often that is useful actually)

I will leave the table idea for others to comment - I actually think  
in the end there are only a few rules to learn and then you will find  
yourself translating easily (not that those rules should not go in a  
cheat sheet somewhere - that's probably a good idea).


With:
NSDictionary.dictionaryWithObjectsAndKeys "a", "b", nil

I assume that in the original ObjC method is actually passing an array  
which (it seems) must be terminated by a nil (in objC).
I actually ran across this in another context - passing objects in  
this way - again I will leave others to comment on it, perhaps it is  
an issue.


However why can't you use :

dict = {"b"=>"a"}
=> {"b"=>"a"}

#check class of created dictionary
dict.class
=> NSMutableDictionary

Why use the long winded ObjC form?

If you need a immutable NSDictionary for some reason:
dict = NSDictionary.alloc.initWithDictionary({"a"=>"b", "c" => "d"})
#or if you like typing
dict = NSDictionary.dictionaryWithObjects(["b","d"], forKeys: 
["a","c"],count:1)


(and many other similar methods, I am sure) works fine.

Cheers,
John


On Oct 14, 2009, at 10:03 , B. Ohr wrote:


Hi all!

Using Cocoa in MacRuby is sometimes a hard job, because all  
documentation, examples and sample code is Obj-C. For example, I  
found this piece of code '[NSNumber numberWithBool:NO]' and asked  
myself how to write that in Macruby.


I opened macirb and typed:

> NSNumber.numberWithBool 0
=> false

First I had to laugh and then I thought: Hey implementors of  
macruby, you really did a great job!


What do you think about a table on http://www.macruby.org/ which  
lists all such short (and astonishing) examples. Or even better, why  
not create a command in the services menu which translates a Obj-C  
sequence (by regexp).


BTW, the second example I tried is:

> NSDictionary.dictionaryWithObjectsAndKeys "a", "b", nil

but instead of {"b"=>"a"} I got a seg fault! (ticket is filed)

Greets,
Bernd





___
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] tentative first steps with GCD in macruby

2009-10-20 Thread John Shea

Dear All,

(sorry for the long post)

I have been experimenting a bit with GCD in MacRuby 0.5 beta.

I have managed to get some code working as I would expect it to work,  
and I am wondering if a few of you could provide a sanity check that  
everything i am doing is above board and not the result of unspecified  
behaviour.


My main concern is that when running a set of tasks and collecting the  
results that the collecting itself is not thread safe (in this case  
the << operator). And if it is not thread safe - then what is the best  
way to collect results from dispatched tasks.


But so far it seems to work magically well.

Before I put the code down - here are some initial discoveries  (which  
may have been obvious to everyone else).


1. When running tests you need wait until the threads are finished -  
otherwise the main loop will finish before the output comes back from  
other threads.
I did that with a sleep, but also experimented with looping until an  
array is filled.


2. Scope: Given one of the global system queues :   
gcdq = Dispatch::Queue.concurrent(:default)

and looping over a number of dispatches:
5.times do |index|
gcdq.dispatch {puts index}
end
the task dispatched will hold the last value of index - it will not  
capture the changing value of index - I assume that the task has a  
pointer directly to the index variable.
(an article by Bill Bumgarner http://www.friday.com/bbum/2009/08/29/blocks-tips-tricks/ 
 pointed out something similar in objC - but had a different way of  
solving this)


So to capture that changing index,  I created a Proc then turned it  
back to a block, eg:

5.times do |index|
task = Proc.new {puts index}
gcdq.dispatch &task
end

3. You will notice that in the code below in check = a.run-disp2 that  
the array is returned - I assume empty - and is gradually filled by  
the tasks.


class A
  def run_disp(an_array)
gcdq = Dispatch::Queue.concurrent(:default)
["f","g","h","i", "j"].each_with_index do |val, index|
   task = Proc.new {an_array  << do_something(val, index)}
   gcdq.dispatch &task
  puts "Loaded #{index}"
end
  end

  def run_disp2
an_array = []
gcdq = Dispatch::Queue.concurrent(:default)
["f","g","h","i", "j"].each_with_index do |val, index|
   task = Proc.new {an_array  << do_something(val, index)}
   gcdq.dispatch &task
  puts "Loaded #{index}"
end
an_array
  end

  def do_something(val, index)
#staggered sleeps so as to prove that various tasks finish first
result = val * (index + 1)
case index
when 0, 1
  sleep 2
when 2
  sleep 1
else
  sleep 0
end
puts "yeah baby! #{index}"
result
  end
end

a = A.new
#pass array to be filled
an_array = []
a.run_disp(an_array)
sleep 10
puts "passed array: #{an_array.join(", ")}"

check = a.run_disp2
sleep 10
puts "returned array: #{check.join(", ")}"

#results:
# Loaded 0
# Loaded 1
# Loaded 2
# Loaded 3
# Loaded 4
# yeah baby! 4yeah baby! 3
#
# yeah baby! 2
# yeah baby! 1
# yeah baby! 0
# passed array: , j, hhh, gg, f
# Loaded 0
# Loaded 1
# Loaded 2
# Loaded 3
# Loaded 4
# yeah baby! 3
# yeah baby! 4
# yeah baby! 2
# yeah baby! 0
# yeah baby! 1
# returned array: , j, hhh, f, gg

#assume puts is not transactional.


thanks in advance for any comments / corrections,
John___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


Re: [MacRuby-devel] tentative first steps with GCD in macruby

2009-10-21 Thread John Shea

Hi Lareunt,

thanks very much for the reply, and the corrections.

Thanks for trying it out. Would you be interested to share your  
experiments later, in a website article?
Yep, sure -   I have some real world number crunching to try it on,  
and a number of machines with different numbers of cores - so it  
should be interesting.


Cheers,
John

On Oct 22, 2009, at 3:02 AM, Laurent Sansonetti wrote:


Hi John,

On Oct 20, 2009, at 10:11 AM, John Shea wrote:


Dear All,

(sorry for the long post)

I have been experimenting a bit with GCD in MacRuby 0.5 beta.


Cool!

I have managed to get some code working as I would expect it to  
work, and I am wondering if a few of you could provide a sanity  
check that everything i am doing is above board and not the result  
of unspecified behaviour.


My main concern is that when running a set of tasks and collecting  
the results that the collecting itself is not thread safe (in this  
case the << operator). And if it is not thread safe - then what is  
the best way to collect results from dispatched tasks.


Yes, appending objects to an array from multiple threads is  
definitely not going to work as you would expect.


Typically, you would use a Mutex object to synchronize access to the  
shared variable, but in the GCD world the most common way I believe  
is to use a sequential queue.


ary = []
ary_queue = Queue.new('com.apple.ary')

100.times do
 Queue.concurrent.dispatch do
 n = heavy_compute
 ary_queue.dispatch { ary << n }
 end
end

This way, the heavy_compute code is executed in parallel and  
appending the result to ary is done sequentially.



But so far it seems to work magically well.

Before I put the code down - here are some initial discoveries   
(which may have been obvious to everyone else).


1. When running tests you need wait until the threads are finished  
- otherwise the main loop will finish before the output comes back  
from other threads.
I did that with a sleep, but also experimented with looping until  
an array is filled.


In case you do asynchronous dispatch calls to a sequential queue  
(that you created yourself), doing a synchronous call passing an  
empty block will block until asynchronous blocks are completed.


q = Queue.new('com.apple.ary')
100.times { q.dispatch { heavy_compute } }
q.dispatch(true) {} # wait

In case you use the concurrent queue, AFAIK the only way to wait is  
to use a Group.


g = Dispatch::Group.new
100.times { g.dispatch(Dispatch::Queue.concurrent) { heavy_compute } }
g.wait


2. Scope: Given one of the global system queues :   
gcdq = Dispatch::Queue.concurrent(:default)

and looping over a number of dispatches:
5.times do |index|
gcdq.dispatch {puts index}
end
the task dispatched will hold the last value of index - it will not  
capture the changing value of index - I assume that the task has a  
pointer directly to the index variable.
(an article by Bill Bumgarner http://www.friday.com/bbum/2009/08/29/blocks-tips-tricks/ 
 pointed out something similar in objC - but had a different way of  
solving this)


So to capture that changing index,  I created a Proc then turned it  
back to a block, eg:

5.times do |index|
task = Proc.new {puts index}
gcdq.dispatch &task
end


Good catch, it's actually a problem that needs to be solved. It also  
reproduces with normal Thread objects:


100.times { |i| Thread.new { p i } }

The current workaround for Thread is to pass the variables to #new.

100.times { |i| Thread.new(i) { |i| p i } }

For GCD, I think your idea is the best.

I have been considering a few ways to solve this problem, a naive  
one would be to copy the dynamic variables upon the block  
preparation if the compiler gives us enough hints.


3. You will notice that in the code below in check = a.run-disp2  
that the array is returned - I assume empty - and is gradually  
filled by the tasks.


class A
 def run_disp(an_array)
   gcdq = Dispatch::Queue.concurrent(:default)
   ["f","g","h","i", "j"].each_with_index do |val, index|
  task = Proc.new {an_array  << do_something(val, index)}
  gcdq.dispatch &task
 puts "Loaded #{index}"
   end
 end

 def run_disp2
   an_array = []
   gcdq = Dispatch::Queue.concurrent(:default)
   ["f","g","h","i", "j"].each_with_index do |val, index|
  task = Proc.new {an_array  << do_something(val, index)}
  gcdq.dispatch &task
 puts "Loaded #{index}"
   end
   an_array
 end

 def do_something(val, index)
   #staggered sleeps so as to prove that various tasks finish first
   result = val * (index + 1)
   case index
   when 0, 1
 sleep 2
   when 2
 sleep 1
   else
 sleep 0
   end
   puts "yeah baby! #{index}"
   result
 end
end

a = A.new
#pass array to be filled
an_array = []
a.run_disp(

Re: [MacRuby-devel] Implementing Undo In RaiseMan / MacRuby

2009-10-26 Thread John Shea
Hi Steve,
did you solve this one?
if not perhaps you could post somewhere the MyDocument.rb code for us to
look at?
Cheers,
J

On Sun, Oct 25, 2009 at 7:17 PM, s.ross  wrote:

> I'm trying to implement the RaiseMan example from Aaron Hillegass's book in
> MacRuby. All has gone pretty well until I reached undo. The idea is to
> handle the insertObject message each time a Person is inserted and
> manipulate the undo stack.
>
>   def insertObject(p, inEmployeesAtIndex:index)
> NSLog("adding #{p} to #{employees}") # <= Not called, huh?
> undo = @undoManager
> undo.prepareWithInvocationTarget(self,
> removeObjectFromEmployeesAtIndex:index)
> if !undo.isUndoing
>   undo.setActionName("Insert Person")
> end
> employees.insertObject(p, atIndex:index)
>   end
>
> The Objective-C signature for this is:
>
> - (void)insertObject:(Person *)p inEmployeesAtIndex:(int)index
>
> Works in Objective-C but in my Ruby, the method is not recognized as a
> handler to be invoked when a Person object is to be inserted in the
> employees array. I should note that I created the employees array using Ruby
> syntax:
>
> @employees ||= []
>
> Changing this to:
>
> @employees ||= NSMutableArray.alloc.init
>
> makes no difference in this scenario.
>
> Any hints with respect to what I'm missing here?
>
> Thanks,
>
> Steve
>
>
> ___
> 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] Implementing Undo In RaiseMan / MacRuby

2009-10-27 Thread John Shea
Steve,

I am not sure what stage you are at with your example, I originally did this
without using an array controller, and the undoing worked fine.

I just threw together a version with an array controller - and the
insertObject(person,
inEmployeesAtIndex:index) and remove methods are being called by the array
controller - however they seem to be passing the index as a nil. Perhaps
this is what Ernest was talking about - an unboxing issue??
Undoing initially works.

Selecting the second row, and then pressing insert causes a crash into the
debugger - so perhaps again some issue with what method the array controller
is calling or trying to call  (and the vars it is trying to pass)  - as
Ernest implied (?).

Note that this experiment was still with 0.4.
Perhaps it works ok in later versions?

I personally have not come across this issue before because I never use the
arraycontroller method insert and remove - I always have my own controller
methods - usually I want to check other things before adding or removing (I
believe later in the book the array controller methods are replaced with own
methods).

Not a solution but perhaps you can work around it, by using your own
controller actions, and then exploring the undo aspects?

Cheers,
John

On Mon, Oct 26, 2009 at 4:06 PM, s.ross  wrote:

> John--
>
> I've started a github repo at http://github.com/sxross/raiseman-rb, but it
> doesn't yet reflect that I can now do initial editing of an inserted row,
> but undo is not there yet.
>
> Thanks,
>
> Steve
>
>
> On Oct 26, 2009, at 1:22 AM, John Shea wrote:
>
> Hi Steve,
> did you solve this one?
> if not perhaps you could post somewhere the MyDocument.rb code for us to
> look at?
> Cheers,
> J
>
> On Sun, Oct 25, 2009 at 7:17 PM, s.ross  wrote:
>
>> I'm trying to implement the RaiseMan example from Aaron Hillegass's book
>> in MacRuby. All has gone pretty well until I reached undo. The idea is to
>> handle the insertObject message each time a Person is inserted and
>> manipulate the undo stack.
>>
>>   def insertObject(p, inEmployeesAtIndex:index)
>> NSLog("adding #{p} to #{employees}") # <= Not called, huh?
>> undo = @undoManager
>> undo.prepareWithInvocationTarget(self,
>> removeObjectFromEmployeesAtIndex:index)
>> if !undo.isUndoing
>>   undo.setActionName("Insert Person")
>> end
>> employees.insertObject(p, atIndex:index)
>>   end
>>
>> The Objective-C signature for this is:
>>
>> - (void)insertObject:(Person *)p inEmployeesAtIndex:(int)index
>>
>> Works in Objective-C but in my Ruby, the method is not recognized as a
>> handler to be invoked when a Person object is to be inserted in the
>> employees array. I should note that I created the employees array using Ruby
>> syntax:
>>
>> @employees ||= []
>>
>> Changing this to:
>>
>> @employees ||= NSMutableArray.alloc.init
>>
>> makes no difference in this scenario.
>>
>> Any hints with respect to what I'm missing here?
>>
>> Thanks,
>>
>> Steve
>>
>>
>> ___
>> 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] spotlight - MDItemRef

2009-10-28 Thread John Shea
I always assumed (with no direct evidence) that it was because in  
Ruby, constants have to start with an uppercase letter, and so to  
match various method signatures/types sent through BridgeSupport,  
constant types must be passed as constant types.


Anyway for supported frameworks capitalising the constant always seems  
to work.


BridgeSupport is an amazing piece of work in my opinion - worksk (and  
work very well) almost transparent to the developer.


Actually am just assuming that the new Applescript methods use  
BridgeSupport? In which case BridgeSupport should just get better.


HTH
J


On Oct 28, 2009, at 10:31 , Allison Newman wrote:

I'm probably asking a really dumb question here - but I haven't used  
bridgesupport very much...
Is there a reason why the constant in the example that fails starts  
with an upper case K, rather than keeping the lower case k given in  
the framework?


Alli

On Wednesday, October 28, 2009, at 01:31AM, "Laurent Sansonetti" > wrote:

Hi Alan,

I'm afraid the MD* APIs haven't been covered by BridgeSupport yet, so
it may not be possible to call it directly from MacRuby at this  
point.

I would recommend to file a bug at http://bugreporter.apple.com so
that we can consider this for a future Mac OS X release, and to wrap
this C API into an Objective-C class that you can call from MacRuby  
in

the meantime.

Laurent

On Oct 27, 2009, at 5:13 PM, Alan Skipp wrote:


Would anyone be able to give me a hint on how to get the following
objective-c code working with macruby. The code uses spotlight to
extract metadata from a file.

MDItemRef inspectedRef =
MDItemCreate(kCFAllocatorDefault,(CFStringRef)path);
CFArrayRef attributeNames = MDItemCopyAttributeNames(inspectedRef);

NSLog(@"%@", (NSArray*)attributeNames);


I was hoping that including the 'CoreServices' framework would work,
but
no joy.


framework 'CoreServices'

=> true

item = MDItemCreate(KCFAllocatorDefault, '/Users/alan/Desktop/
test.jpg')

NameError: uninitialized constant KCFAllocatorDefault
from core:in `const_missing:'
from (irb):2:in `'
from core:in `eval:'
from core:in `evaluate:'
--
Alan Skipp
[email protected]

--
http://www.fastmail.fm - IMAP accessible web-mail

___
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] Speed

2009-11-23 Thread John Shea
Hi Uliano,

The way I get the JIT to preprocess your fib code is simply to call the method 
once. For example I wrapped your code in a class (not that I am saying that it 
is necessary to do this - its just the first thing i tried and it worked) and 
then.

(for example)
afib.fib_iter(sum,10)

and then time test with afib.fib_iter(sum,4_000_000)

I think you have to also keep in mind that the method dispatch in macruby is a 
work in progress and that method dispatch time is always going to be different 
between different ruby implementations.
In your code for example passing a block and dispatching that block always with 
yield could be a performance stopper - when i rewrote your original  code to 
not have these yield calls I got much improved performance:

#command line: ruby or  macruby fib.rb

#ruby 1.8.7
recursive
sum = 
4613732
time = 
18.795026
iterative
sum = 
4613732
time = 
3.0e-05


#macruby beta 0.5-2
#no pre compile
recursive
sum = 
4613732
time = 
0.585983
iterative
sum = 
4613732
time = 
0.007148

#macruby beta 0.5-2
#run it once first
recursive
sum = 
4613732
time = 
0.591092
iterative
sum = 
4613732
time = 
0.002592


#macruby beta 0.5-2
#run it once first and using code without yields.

recursive
sum = 
4613732
time = 
0.586312
iterative
sum = 
4613732
time = 
3.0e-06

hope that helps,
John

On Nov 23, 2009, at 8:30 , Uliano Guerrini wrote:

> Thank you all
> 
> I didn't realize that JIT in macruby is compiling on the fly the code piece a 
> piece (I thought that a source file was the compilation unit) and so JIT time 
> to compile the block was inside my time metrics
> 
> I re-run the test looping many times and the results are speaking for 
> themselfs:
> 
> uliano$ macruby fib.rb 
> sum of even Fibonacci less than 400 = 4613732
> time = 0.637182
> uliano$ /usr/bin/ruby fib.rb 
> sum of even Fibonacci less than 400 = 4613732
> time = 4.710929
> uliano$ ruby fib.rb   # this is Ruby 1.9.1 from 
> macports
> sum of even Fibonacci less than 400 = 4613732
> time = 0.660384
> uliano$ macrubyc -o fib fib.rb
> uliano$ ./fib
> sum of even Fibonacci less than 400 = 4613732
> time = 0.61873
> 
> 
> 
> 
> 
> ___
> 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] [MacRuby] #447: GCD Crashes

2009-11-23 Thread John Shea
Hi Pete,

I imagine that this bug is similar to one I posted (420). I was getting
similar behaviour and things much improved when I unrolled the loop. Maybe
you could try that? (or try what i suggest below).

I am waiting with bated breath to see Laurent's GCD code in the macruby
version of Sinatra.

I imagine that it is actually quite hard to turn ruby blocks into C blocks -
normally everything would be copied to the stack with C blocks - unless
manually copied to the heap - but probably in macruby they have to be
immediately copied to the heap. And then what to do with all the scoped (but
in C static) variables? In C there are complicated inferred return block
types which sometimes work, automatic releases sometimes, sometimes manual
releases are necessary of queues (i.e GCD does not use GC) - it all seems
rather complicated.

There is a note somewhere I believe in the macruby gcd code about how it
might be bad to access instance variables from a queue - none the less when
using Laurent's web_server.rb code as model - the threading bit - and doing
something similar in GCD - I got something working ok.

Using threads (as per the example) and GCD I could get some speed
improvements - however on a 2 core  machine - those improvements were not
much - i actually don't expect that much on only 2 cores - since there is a
hell of a lot of other threading happening (eg GC) even if we don't consider
the demands that the rest of the OS is putting on the processor.

So with 2 cores I found best results to limit to two GCD serial queues.
cpuCount = NSProcessInfo.processInfo.processorCount
is a helpful command in this regard.

I would be very interested to see your results if you try this out. One
thing to watch out for variable allocations within the queue block - the
variables might not be instantly available (like the next line).

>From what i have read there are many resources in the OS which can stall
when there are too many processes trying to access them - so perhaps a good
way in the future is actually to wrap all resource access in semaphores -
adjusted by cpu count.


Cheers,
J





On Mon, Nov 23, 2009 at 1:27 AM, MacRuby wrote:

> #447: GCD Crashes
>
> --+-
>  Reporter:  p...@…|   Owner:  lsansone...@…
> Type:  defect|  Status:  new
>  Priority:  major |   Milestone:  MacRuby 0.5
> Component:  MacRuby   |Keywords:
>
> --+-
>  I've been playing with the GCD support in 0.5, and I can get it to
>  misbehave consistently with a fairly simple script (attached.)
>
>  Various things happen when this script is run. Sometimes I get a crash
>  with the assertion below, sometimes I get a seg fault.
>
>  Assertion failed: ((arity.max == -1) | | (argc <= arity.max)), function
>  !__rb_vm_fix_args, file dispatcher.cpp, line 29.
>
>  Sometimes it runs mostly ok, but spits out NaN instead of the correct
>  value at random intervals.
>
>  Something to do with the block being prematurely garbage collected
>  perhaps?
>
> --
> Ticket URL: 
> MacRuby 
>
> ___
> 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] [MacRuby] #447: GCD Crashes

2009-11-23 Thread John Shea
>
>
> Did you  mean the other way around?  You seem to be discussing how to turn
> C blocks into Ruby blocks.
>

hmmm? no that was not my intent.

No I assume at some stage the ruby block has to be turned into a C block
with associated scope - and from my limited knowledge on GCD that does not
seem so easy.

But Ernie - I'd love for you to explain how its all done! ;-).
I mean if you have the time - it would be great to know maybe on pseudo
code/architectural level how it all works. ruby block to c block, __block
vars, scope etc, etc, I am a bit scratching in the dark here.

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


Re: [MacRuby-devel] [MacRuby] #447: GCD Crashes

2009-11-23 Thread John Shea
Hi again, 

thanks for the code ..

I am actually not trying to make a point - just trying to learn, and start a 
discussion that leads to learning.

since the code below means nothing to me - thats probably a good place for me 
to start.

Cheers,
J

On Nov 23, 2009, at 9:58 PM, Ernest N. Prabhakar, Ph.D. wrote:

> Hi John,
> 
> On Nov 23, 2009, at 12:55 PM, John Shea wrote:
>> No I assume at some stage the ruby block has to be turned into a C block 
>> with associated scope - and from my limited knowledge on GCD that does not 
>> seem so easy. 
> 
> Again, I think I'm still missing your point. In the context of GCD, this is a 
> non-issue since you don't *have* to use C blocks.  Instead, GCD provides a 
> function pointer + context pointer API, which is what MacRuby uses:
> 
> http://github.com/masterkain/macruby/blob/master/gcd.c
> 
>> if (RTEST(synchronous)){
>> dispatch_sync_f(RQueue(self)->queue, (void *)block,
>>  rb_queue_dispatcher);
>> } 
>> else {
>> dispatch_async_f(RQueue(self)->queue, (void *)block,
>>  rb_queue_dispatcher);
>> }
> 
> That is, C just treats the Ruby block as a data pointer.
> 
> -- Ernie P.
> 
> 
> ___
> 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] Assertion failed in rb_vm_super_lookup

2009-11-27 Thread John Shea
Hi Gareth,

Have a look at the examples in Developer/Examples/Ruby/MacRuby - there are
good examples there which might be useful for you.

In this case your init method is an obvious problem, it must (as in
objective C) return self.

The super call is interesting because normally in ruby it will call your
current method in the super class and magically pass on parameters you had
to the current object's method to the super class.

I cannot find an example of super.method in Pickaxe, but nonetheless
super.initWithSomething(params) - has worked fine for me. Someone will
correct me, I am sure, i this is wrong.

so you could try:
def init
if (super initWithWindowNibName('preferences'))
#initialisation stuff
return self
end
nil
end

or more or less the same:

def init
result = super.initWithWindowNibName('Preferences')
if result
#other initialisation
end
result
end

cheers,
John

On Fri, Nov 27, 2009 at 12:51 AM, Gareth Townsend wrote:

> Hi,
>
> I've just started playing with MacRuby. So please bear with me, there's
> every chance I'm doing something stupid :-) I'm using 0.5 beta 2.
>
> I'm building a simple Cocoa App (http://github.com/quamen/noise) and am
> running into some problems while trying to set up a Preference Pane.
>
> Specifically this error:
>
> > Assertion failed: (m != NULL), function rb_vm_super_lookup, file
> dispatcher.cpp, line 228.
>
> Followed by a whole heap of warnings that seem to hard coded to Laurent's
> machine
>
> Program received signal:  “SIGABRT”.
> > sharedlibrary apply-load-rules all
> > warning: Could not find object file
> "/Users/lrz/src/macruby-clean/array.o" - no debug information available for
> "array.c".
> >
> > warning: Could not find object file
> "/Users/lrz/src/macruby-clean/bignum.o" - no debug information available for
> "bignum.c".
> >
> > ...
>
>
> This occurs when I try to instantiate an NSWindowController subclass. My
> Code:
>
> > def open_preferences(sender)
> >   NSLog('open preferences')
> >   preference_controller ||= PreferencesController.new
> >   preference_controller.showWindow(self)
> > end
>
> > class PreferencesController < NSWindowController
> >   def init
> >   if (super initWithWindowNibName('preferences'))
> >   self
> >   else
> >   nil
> >   end
> >   end
> >
> > end
>
>
> I have a .xib file called 'preferences.xib'
>
> So can anyone spot something stupid? If not, how should I go about
> debugging this?
>
> Cheers,
> Gareth Townsend
> http://www.garethtownsend.info
> http://www.melbournecocoaheads.com
>
>
>
>
> ___
> 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] floats in core data

2009-11-27 Thread John Shea
Hi all,

does any one know whether there is an issue with binding to floats, doubles in 
core data with macruby?

For example:

1 I firstly, create an attribute foo which is set as a double or a float in the 
core data model
2. i bind it to a table column
3. I set foo to 300.3 in code (not through the user interface)
4. it comes through as 1 (or 1.00 if formatted - which is probably neither here 
nor there)

If i do the same but set the attribute to be of type decimal - then the number 
300.3 comes through fine.

The problem then is that is that the class of foo is NSDecimalNumber - and its 
really painful doing calculations with NSDecimalNumbers given that normal 
arithmetic operators do not work.
I haven't found it to be that accurate either (at least in Objective C) - 
compared to ruby floats.

The strange thing is that both end up (in macruby) inheriting from NSNumber - 
but somehow the binding cannot make sense of it.

Is it possible that there is a non macruby translation going on? - an unboxing 
- because the binding/kvc access thinks that foo is a float? (which it might 
be, in the persistent store - but does not seem to be by the time its accessed).

I can think of work arounds - but i thought i better check with the experts 
first ;-).

Cheers,
J

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


Re: [MacRuby-devel] floats in core data

2009-11-28 Thread John Shea
Hi Laurent,

(sorry for the longish post)

I did some simple tests where the bound variable is not actually bound to a 
CoreData store, but to a method in the custom NSManagedObject class..

(btw - I am not sure if anyone else noticed but a difference between 0.4 and 
0.5, is that when binding to custom methods now, the methods have to be 
mentioned in the valueForUndefinedKey method of the NSManagedObject - before 
they did not need to be - but maybe in 0.4, this was a lucky time dependency, 
with the method being loaded before being queried by the view).

- Returning a (ruby) number like 45.3 will not be displayed in the column (with 
and without formatter) or in fact a plain NSTextField (so it does not seem to 
be a table cell issue) but returning 
NSDecimalNumber.decimalNumberWithString("45.3") - will be displayed correctly 
in both.

- Same issue when binding to a class with only NSObject as the super.

- I also did do some test with the core data stack and KVC/KVO, binding etc and 
everything worked ok. I now think this issue has nothing to do with CoreData.

- My current suspicion is that the NSTextField is being sent a setObjectValue 
message which works fine with NSDecimalNumbers - it does not work with MacRuby 
Floats, or with NSNumbers - although i would expect it to since they are 
objects.

(bolds added by me for comprehension)

irb(main):005:0> framework "Cocoa"
=> true
irb(main):006:0> tf = NSTextField.alloc.init
=> #
irb(main):007:0> num = NSNumber.numberWithFloat(23.3)
=> 23.292370605
irb(main):008:0> tf.setObjectValue(num)
=> #
irb(main):009:0> p tf.stringValue
"0"
=> "0"
irb(main):010:0> tf.setFloatValue(23.3)
=> #
irb(main):011:0> p tf.stringValue
"23.2923706055"
=> "23.2923706055"

I will add this to the MacRuby bugs a bit later.


re NSDecimalNumber -> leaving it "untouched" as you said,  is,  in my opinion 
the right thing, it would be too confusing for it to have different behavior 
than what is in the docs.

Cheers,
John





On Nov 27, 2009, at 9:22 PM, Laurent Sansonetti wrote:

> Hi John,
> 
> This may be a bug in MacRuby, I don't know bindings well enough. It would be 
> cool if you could reduce the problem into a small Ruby script.
> 
> We are indeed unboxing NSNumbers automatically. NSDecimalNumber seems to be 
> left untouched, which could explain why the normal arithmetic operators do 
> not work.
> 
> Laurent
> 
> On Nov 27, 2009, at 7:50 AM, John Shea wrote:
> 
>> Hi all,
>> 
>> does any one know whether there is an issue with binding to floats, doubles 
>> in core data with macruby?
>> 
>> For example:
>> 
>> 1 I firstly, create an attribute foo which is set as a double or a float in 
>> the core data model
>> 2. i bind it to a table column
>> 3. I set foo to 300.3 in code (not through the user interface)
>> 4. it comes through as 1 (or 1.00 if formatted - which is probably neither 
>> here nor there)
>> 
>> If i do the same but set the attribute to be of type decimal - then the 
>> number 300.3 comes through fine.
>> 
>> The problem then is that is that the class of foo is NSDecimalNumber - and 
>> its really painful doing calculations with NSDecimalNumbers given that 
>> normal arithmetic operators do not work.
>> I haven't found it to be that accurate either (at least in Objective C) - 
>> compared to ruby floats.
>> 
>> The strange thing is that both end up (in macruby) inheriting from NSNumber 
>> - but somehow the binding cannot make sense of it.
>> 
>> Is it possible that there is a non macruby translation going on? - an 
>> unboxing - because the binding/kvc access thinks that foo is a float? (which 
>> it might be, in the persistent store - but does not seem to be by the time 
>> its accessed).
>> 
>> I can think of work arounds - but i thought i better check with the experts 
>> first ;-).
>> 
>> Cheers,
>> J
>> 
>> ___
>> 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] Xcode and Interface Builder: action and outlets not showing up

2009-12-04 Thread John Shea
Yes, as you have probably realised you need to reinstall MacRuby.
In my case it did not affect my iphone SDK after reinstalling MacRuby.

J

On Dec 4, 2009, at 13:00 , Robinson, John MD PhD wrote:

> Hi all,
> 
> I am new to the list.
> 
> While working through Geoffrey Grosenbach's tutorial on peepcode, I began to 
> experience the following problems in IB. I lost autocomplete in the class 
> identity textbox and the outlets/actions of the class were not avaiable. 
> Conclusion: IB isn't recognizing my classes. This seems to have started after 
> loading the iphone sdk, which upgraded Xcode from 3.1 -> 3.2.
> 
> Thanks,
> 
> ~JR
> 
> 
> 
> 
> 
> ___
> 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] Would a macruby-newbie List Be Worthwhile?

2009-12-16 Thread John Shea
Hi Steve,

I agree with Ernie.

I am always happy to answer questions if I think the person is not rude, or 
asking me to write their entire app - and that is, so far, rare on this list.

Usually when I get it wrong other people pipe up ;-).

Some seemingly simple questions do often lead to a bug fix too.

Regarding your example, I not sure whether you did it or not, here is what I 
would do (i just tried this - so I know it works).

(Apropos Core Data: I have created a Core Data Document Template for XCode - it 
probably needs a bit of testing - but if anyone is interested let me know and i 
will post it somewhere)

Imagine you have created a (non document) app with out any CoreData 
infrastructure, then:

1. Create a new file in your project - standard ruby class, name it AppDelegate 
(or whatever you like).

2. Copy and paste the boiler plate code that you would get if you had an 
AppDelegate created from the Core Data template (eg from another project) to 
this file,  change the name of the xml file you are saving to (about line 50 in 
the current template). Also add/create a new mapping model (thats in the 
resource section when creating a new file), it will be used automatically.

or alternatively:

1&2. Create a new CoreData project from the template, and just drag these two 
files into the old project (in Xcode - not the finder).

3. in IB drag an nsobject into the ib project from the library, set the class 
to be the AppDelegate (or whatever you class is called that holds the 
boilerplate Core Data stuff above), also set the window iboutlet in the app 
delegate to the window (not actually sure if this is necessary - but the 
template comes like that). And make sure the application delegates to your app 
delegate (control drag from the application to your new app delegate).
4. Continue as you would normally with a core data app.

The second part, filling with data (presumably you will only need to do this 
once, because then the data can be saved with the app).
There are many ways to add data.

The easiest I reckon, is to add a method to the AppDelegate - called 
applicationDidFinishLaunching(notification) (delegated from the application 
singleton) and in that method you can do something like: 
new_student = NSEntityDescription.insertNewObjectForEntityForName("Student", 
inManagedObjectContext:self.managedObjectContext). 
Then set the attributes for that obj, eg student.name = "Bill".

This was at a high-ish level  - if there is something that you don't 
understand, feel free to ask - but ask in the next 7 hours, because I will be 
traveling and incommunicado for a couple of days.


Cheers,
John


On Dec 16, 2009, at 7:37 , steve ross wrote:

> Thanks for your feedback...
> 
> On Dec 15, 2009, at 4:19 PM, Ernest N. Prabhakar, Ph.D. wrote:
>> 
>> Hi "S",
> 
> Point taken :)
> 
>>> Would a newbie list be worth creating?
>> 
>> I would encourage you to just go ahead and ask on this list, for several 
>> reasons:
>> 
>> a) The people who would answer are here, so they may as well answer
> 
> That's what someone says every time somebody else suggests forking a list. I 
> hope it's the right answer because a lot of my questions would be off topic 
> both on this list and the Cocoa Developers list.
> 
>> b) It could be a bug, in which case it belongs here
> 
> Yeah, but at this point, I think many of us can tell when it's our own fault 
> :)
> 
>> c) It helps us understand usage issues, which may inform features and 
>> documentation
> 
> Again, point taken.
> 
>> The more interesting question to me is when do we create a macruby-users 
>> list for those using the "stable" version -- or move development OF macruby 
>> to a "macruby-core"?
>> 
>> I guess it depends on when MacRuby is stable enough and popular enough.  At 
>> any rate, it isn't yet.
>> 
>> -enp
>> 
>> 
>> On Dec 15, 2009, at 11:21 AM, s.ross wrote:
>> 
>>> There are a number of questions I know I have coming from a Ruby/Rails and 
>>> not a Cocoa background. These questions can be difficult to answer in the 
>>> context of Objective-C (and heck, Ruby makes a lot of the Objective-C 
>>> syntactic vinegar just go away). They are also not specifically about 
>>> MacRuby, but rather about how it interacts with the framework.
>>> 
>>> Because MacRuby can open up Cocoa to developers who really didn't want to 
>>> mess around with [[obj alloc] init] and all that stuff. Many of you on this 
>>> list did go through that learning experience but have already answered 
>>> these same questions before in a different context but shouldn't be imposed 
>>> upon to answer them again. Would a newbie list be worth creating? I find 
>>> myself coming up with seemingly stupid questions that I simply don't want 
>>> to trouble the list with but that take hours to dig out of the 
>>> documentation. That would be the proposed purpose. Post some code, expected 
>>> results, and what's actually happening.
>>> 
>>> Maybe an example: I want a single pane Core Data ap

Re: [MacRuby-devel] Would a macruby-newbie List Be Worthwhile?

2009-12-16 Thread John Shea
keys"
p "#{floater.energy.class} #{floater.valueForKey("energy").class}"
p "#{floater.work.class} #{floater.valueForKey("work").class}"

p "set"
floater.energy = 456.67
p floater.energy
p "#{floater.energy.class} #{floater.valueForKey("energy").class}"

floater.work = 456.67
p floater.work #changes to NSDecimalNumber
p "#{floater.work.class} #{floater.valueForKey("work").class}"

avalue = Copier.new

options = {NSAllowsEditingMultipleValuesSelectionBindingOption => true}
avalue.bind("energy", toObject:floater, withKeyPath:"energy", options:options)
avalue.bind("work", toObject:floater, withKeyPath:"work", options:options)
obie = Observa.new(floater)

2.times do
  floater.setValue(rand(10) * 1.234, forKey:"work")
  sleep 1
  p "avalue work #{avalue.work}. #{avalue.work.class}"
end
p "--"
2.times do
  floater.setValue(rand(10) * 1.234, forKey:"energy")
  sleep 1
  p "avalue energy #{avalue.energy}. #{avalue.energy.class}"
end


On Dec 17, 2009, at 12:40 AM, Laurent Sansonetti wrote:

> 
> On Dec 16, 2009, at 2:25 PM, Brian Chapados wrote:
> 
>> On Wed, Dec 16, 2009 at 9:11 AM, steve ross  wrote:
>>> On Dec 16, 2009, at 1:07 AM, John Shea wrote:
>>>> 
>>>> The second part, filling with data (presumably you will only need to do 
>>>> this once, because then the data can be saved with the app).
>>>> There are many ways to add data.
>>>> 
>>>> The easiest I reckon, is to add a method to the AppDelegate - called 
>>>> applicationDidFinishLaunching(notification) (delegated from the 
>>>> application singleton) and in that method you can do something like:
>>>> new_student = 
>>>> NSEntityDescription.insertNewObjectForEntityForName("Student", 
>>>> inManagedObjectContext:self.managedObjectContext).
>>>> Then set the attributes for that obj, eg student.name = "Bill".
>>> 
>>> Let me be more specific about *why* this is important to me. My app goes 
>>> out to a Web Service for data, so I have to fill some of it in 
>>> programmatically, then it refreshes only occasionally. I decided this would 
>>> be best in the controller, so it could be triggered by the user. To emulate 
>>> that, I wanted to prepopulate the managedObject collection, and that I did 
>>> in awakeFromNib. Warning: Make sure to call super! So what it boiled down 
>>> to what this method in the controller:
>>> 
>>> def new_image(image = {})
>>>   object = NSEntityDescription.insertNewObjectForEntityForName("Image",
>>> inManagedObjectContext:managedObjectContext)
>>>   object.setValue image[:fileid], forKey: 'fileid'
>>>   object.setValue image[:title], forKey: 'title'
>>>   puts "#{object} #{object.fileid} : #{object.title}"
>>> end
>>> 
>>> I used the setters explicitly when I was confused about why the bound 
>>> tableview was blank. I'm beginning to get this a bit more under control, 
>>> but the IB/CoreData/Cocoa Bindings is even magical to a Ruby person :)
>>> 
>>> See? I told you it was a dumb question.
>>> 
>>> Thanks,
>>> 
>>> Steve
>>> ___
>>> MacRuby-devel mailing list
>>> [email protected]
>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>> 
>> 
>> If MacRuby is your first exposure to mac programming and all of the
>> associated tools and techniques, starting out by jumping into an
>> IB-based project that uses CoreData & Bindings is going to be really
>> confusing.
>> 
>> I'd break up the tasks into pieces small enough that you can actually
>> understand what's going on. You shouldn't feel like things are
>> happening "magically". If that is the case, then try to take a step
>> back and figure out how the magic trick works.
>> 
>> For example, if you want to tackle CoreData first, then start with
>> just CoreData.  Build a command-line program that creates a CoreData
>> stack by reading in your compiled .xcdatamodel (or create the model in
>> code!), add some data, and save it.  Once you've got that working,
>> then make it download data from your web service and save it.
>> 
>> Here is the approach I would take:
>> 
>> 1. If you haven't already, read through the Core Data Programming guide:
>> http://develope

Re: [MacRuby-devel] Cocoa Binding to NSArrayController

2010-01-12 Thread John Shea
Perhaps it is this bug here: https://www.macruby.org/trac/ticket/473

In my case with the current 0.5 beta2 no float or integer binding to nscontrol 
works (I get all 1's) unless the float or integer is converted to an 
NSDecimalNumber using a ValueTransformer.
This is what i use for each float binding as a work around:

class ToDecimalTransformer < NSValueTransformer 
def self.transformedValueClass; NSDecimalNumber.class; end

def self.allowsReverseTransformation; true; end 

def transformedValue(value)
NSDecimalNumber.decimalNumberWithString(value.to_s)
 end
  
def reverseTransformedValue(value)
new_val = value.to_f
end
end

HTH,
John

On Jan 12, 2010, at 7:33 PM, steve ross wrote:

> On Jan 11, 2010, at 11:13 AM, isaac kearse wrote:
>> Looks like you're bypassing the to_i conversion of @number by calling 
>> instance_variable_set directly, but I'd guess that the problem is somewhere 
>> else in the app.
>> Any chance you could put the whole thing up on github?
>> 
>> Cheers,
>> Isaac
> 
> I put together an Objective-C version of this same thing and checked it into 
> the github project for comparison. It works. I'm sure there's something 
> different in how I'm using it, but I can't see what. The project is at:
> 
> [email protected]:sxross/MacRuby-Array-Cocoa-Array-Binding.git
> 
> That's both MacRuby and Objective-C. Any pointers to my blind spot are 
> appreciated :)
> 
> Steve
> 
>> On Tue, Jan 12, 2010 at 6:41 AM, steve ross  wrote:
>> I wrote a simple controller that binds to an NSTableView. In the tableview, 
>> a column has an NSNumberFormatter (in IB), but the column is what's bound. 
>> It's bound to LightboxController.managedObjects:number. The managedObjects 
>> collection contains a collection of Lightbox objects, that have a number 
>> (Fixnum, when examined) and a title (string). The title displays fine, but 
>> the number always displays as 1. Changing the number field to a string and 
>> removing the NSNumberFormatter produces the correct display, but of course, 
>> the sort order is string ordering rather than numeric.
>> 
>> Here is the code. Can anyone tell me what I'm missing here?
>> 
>> https://gist.github.com/5d490492a814eccd26b2
>> 
>> Thx,
>> 
>> Steve
> 
> 
> ___
> 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] OpenGL/GLUT Bridgesupport

2010-01-21 Thread John Shea
Yes as far as I know bridge support does not support GLUT.

So you (obviously) have two other options other than gen_bridge_metadata (which 
I gave up on after a few tries) :

- don't use GLUT - use the equivalent (set of) non GLUT openGL calls
- place the GLUT calls in an ObjC class - and call out to that class from 
MacRuby

you might find that the second option is quite quick - i found that for some 
openGL calls (but not all) that dispatching to my own bridge class which then 
called opengl functions was quicker than going through BridgeSupport.

There are other good reasons to have your own bridge class anyway - i imagine 
that BridgeSupport is always going to be lagging Cocoa a bit (eg Core Animation 
constants), and it might just be easier allocating OpenGL texture memory in 
ObjC (well I still use objC for that)

HTH,
J


On Jan 20, 2010, at 8:14 PM, Jonathan Waddilove wrote:

> Hi, I'm back to using MacRuby again and I'm confused about Bridge Support.
> 
> I have been using the excellent sojaster port of the Cocoa OpenGL example to 
> help develop an OpenGL playpen. However, when I started using glut calls 
> (glutBitmapCharacter, glutStrokeString, etc) I started to get problems.
> 
> It seems that the OpenGL glut.framework (10.6.2) doesn't include bridge 
> support. I've tried using gen_bridge_metadata to add bridge support but 
> without success.
> 
> Should glut work in MacRuby? How does one add BridgeSupport to the Apple 
> shipped frameworks?
> 
> Sorry if I have missed some very obvious step.
> 
> regards and thanks,  Jonathan
> 
> ___
> 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] OpenGL/GLUT Bridgesupport

2010-01-22 Thread John Shea

Jonathan,

I made some games in opengl this time last year (which now seem quite  
naive, as i did not know opengl or cocoa, so they could do with a good  
refactor).


I do not know if they work with the current version of macruby but they  
are on my idisk:


www.johnmacshea.org

navigate thru MacRuby / Game Related / Mine

Two 2D games CarNage8 and IcePhage9 are there.

They do screen setup, texture loading, writing text to opengl scenes (two  
different ways), canned explosions sometimes and particle effects for  
other explosions.


They do not use VAs or VBOs - but I do have some test projects which use  
VAs and VBOs, and a 3D test (which uses an exported c header file (from  
Cheetah 3D) holding vertex arrays).


Let me know if you are interested and I will dig them up and send them to  
you (only tested on MacRuby 0.4 however).


In that game related folder you will also see translations from other  
people's opengl work (also only tested on 0.4)


Cheers,
J


On Fri, 22 Jan 2010 09:32:57 +0100, Jonathan Waddilove  
 wrote:



John,

Thank you for the response. GLUT won't be my first choice but I'm trying  
to follow the examples in the SuperBible.


I'm wondering what the plan is to support all the 'standard' frameworks  
in MacRuby is? Should I be able to process the GLUT.framework with  
gen_bridge_metadata?


Meanwhile I will look at providing my own wrapper class as you suggest.  
As you say this provides a flexible way of handling any framework that  
lacks bridge support.


Many thank, Jonathan

On 21 Jan 2010, at 20:56, John Shea wrote:


Yes as far as I know bridge support does not support GLUT.

So you (obviously) have two other options other than  
gen_bridge_metadata (which I gave up on after a few tries) :


- don't use GLUT - use the equivalent (set of) non GLUT openGL calls
- place the GLUT calls in an ObjC class - and call out to that class  
from MacRuby


you might find that the second option is quite quick - i found that for  
some openGL calls (but not all) that dispatching to my own bridge class  
which then called opengl functions was quicker than going through  
BridgeSupport.


There are other good reasons to have your own bridge class anyway - i  
imagine that BridgeSupport is always going to be lagging Cocoa a bit  
(eg Core Animation constants), and it might just be easier allocating  
OpenGL texture memory in ObjC (well I still use objC for that)


HTH,
J


On Jan 20, 2010, at 8:14 PM, Jonathan Waddilove wrote:

Hi, I'm back to using MacRuby again and I'm confused about Bridge  
Support.


I have been using the excellent sojaster port of the Cocoa OpenGL  
example to help develop an OpenGL playpen. However, when I started  
using glut calls (glutBitmapCharacter, glutStrokeString, etc) I  
started to get problems.


It seems that the OpenGL glut.framework (10.6.2) doesn't include  
bridge support. I've tried using gen_bridge_metadata to add bridge  
support but without success.


Should glut work in MacRuby? How does one add BridgeSupport to the  
Apple shipped frameworks?


Sorry if I have missed some very obvious step.

regards and thanks,  Jonathan

___
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] OpenGL/GLUT Bridgesupport

2010-01-22 Thread John Shea



Thank you again for offering the additional resources. It would be great if you wanted to add them to your idisc.sure.I did find a copy of your excellent presentation "Building Games with MacRuby and OpenGL", I must work through the slides again. Did you consider sharing your game tools? The presentation would make a very useful basis for a web tutorial on the MacRuby/openGL topic.As far as tools are concerned the only one that ended up being useful in the end was canning particle effects, so you run the explosion, fireworks or whatever and then record a series of images, which you can use for animation later. With IcePhage however it was all on the fly particle effects - canned animation was not necessary - it could do with some optimisation (both in look and efficiency) - and macruby speed increases have probably have improved performance.Is that what you meant by tools?The only other software (sans MacRuby) I used was XCode, TextMate and for 3D experiments Cheetah 3D, some Illustrator & Ria for drawing, graphic converter to clean up the PNGs.Let me know if you meant something else regarding tools.Cheers,JLike you, I'm new to both openGL and MacRuby - my interest is in visualisations rather than games. Right now I'm just greatfull that folks like you are willing to share their hard earned skills.Best wishes, Jonathanjonathan 'at' waddilove.netOn 22 Jan 2010, at 09:28, John Shea wrote:Jonathan,I made some games in opengl this time last year (which now seem quite naive, as i did not know opengl or cocoa, so they could do with a good refactor).I do not know if they work with the current version of macruby but they are on my idisk:www.johnmacshea.orgnavigate thru MacRuby / Game Related / MineTwo 2D games CarNage8 and IcePhage9 are there.They do screen setup, texture loading, writing text to opengl scenes (two different ways), canned explosions sometimes and particle effects for other explosions.They do not use VAs or VBOs - but I do have some test projects which use VAs and VBOs, and a 3D test (which uses an exported c header file (from Cheetah 3D) holding vertex arrays).Let me know if you are interested and I will dig them up and send them to you (only tested on MacRuby 0.4 however).In that game related folder you will also see translations from other people's opengl work (also only tested on 0.4)Cheers,JOn Fri, 22 Jan 2010 09:32:57 +0100, Jonathan Waddilove <[email protected]> wrote:John,Thank you for the response. GLUT won't be my first choice but I'm trying to follow the examples in the SuperBible.I'm wondering what the plan is to support all the 'standard' frameworks in MacRuby is? Should I be able to process the GLUT.framework with gen_bridge_metadata?Meanwhile I will look at providing my own wrapper class as you suggest. As you say this provides a flexible way of handling any framework that lacks bridge support.Many thank, JonathanOn 21 Jan 2010, at 20:56, John Shea wrote:Yes as far as I know bridge support does not support GLUT.So you (obviously) have two other options other than gen_bridge_metadata (which I gave up on after a few tries) :- don't use GLUT - use the equivalent (set of) non GLUT openGL calls- place the GLUT calls in an ObjC class - and call out to that class from MacRubyyou might find that the second option is quite quick - i found that for some openGL calls (but not all) that dispatching to my own bridge class which then called opengl functions was quicker than going through BridgeSupport.There are other good reasons to have your own bridge class anyway - i imagine that BridgeSupport is always going to be lagging Cocoa a bit (eg Core Animation constants), and it might just be easier allocating OpenGL texture memory in ObjC (well I still use objC for that)HTH,JOn Jan 20, 2010, at 8:14 PM, Jonathan Waddilove wrote:Hi, I'm back to using MacRuby again and I'm confused about Bridge Support.I have been using the excellent sojaster port of the Cocoa OpenGL example to help develop an OpenGL playpen. However, when I started using glut calls (glutBitmapCharacter, glutStrokeString, etc) I started to get problems.It seems that the OpenGL glut.framework (10.6.2) doesn't include bridge support. I've tried using gen_bridge_metadata to add bridge support but without success.Should glut work in MacRuby? How does one add BridgeSupport to the Apple shipped frameworks?Sorry if I have missed some very obvious step.regards and thanks,  Jonathan___MacRuby-devel mailing [email protected]://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel___MacRuby-devel mailing [email protected]://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel___MacRuby-devel mailing [email protected]://lists.macosfor

Re: [MacRuby-devel] OpenGL/GLUT Bridgesupport

2010-01-24 Thread John Shea
Hi Jonathan,

yes i discovered that yesterday too.

Changing all of the "i" s to "I"s was not too hard - i do not know if this is a 
change in Pointer types or whatever.

The bigger issue is that this call:
data = CGBitmapContextGetData(context)

no longer seems to return the correct data type (type "C" rather than type "v") 
- perhaps this is a BridgeSupport issue - I do not know, however the fix and 
the reason why i think its a bug, is that you can get all working (once the 
first fix with "i" s are done) by replacing the following code in the 
GLView.load_texture method from:

  context = Tools.sendTexture(imageRef)
  data = CGBitmapContextGetData(context)
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_STORAGE_HINT_APPLE, 
GL_STORAGE_SHARED_APPLE)
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
GL_LINEAR_MIPMAP_LINEAR); 
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE )
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE )
  gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height, GL_BGRA, 
GL_UNSIGNED_INT_8_8_8_8, data)

to

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_STORAGE_HINT_APPLE, 
GL_STORAGE_SHARED_APPLE)
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
GL_LINEAR_MIPMAP_LINEAR); 
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE )
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE )
  Tools.sendTexture(imageRef)

and add to the objc class, in class method sendTexture, before the return 
(which is now superfluous, but i did not change through laziness):

CGContextRelease(context);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height, GL_BGRA, 
GL_UNSIGNED_INT_8_8_8_8, data);

the release is there because i know now that CoreGraphics is not garbage 
collected.

So the very same opengl mipmap call (with same datatype) works fine now, and so 
does the game (IcePhage - and its the same code in CarNage).

Of course you could move most of those opengl calls into the objC method - but 
that might defeat the purpose of limiting the objc code to the minimum.


Cheers,
J


On Jan 23, 2010, at 3:19 PM, Jonathan Waddilove wrote:

> John,
> 
> I've just started to look at your IcPhage9 and CarNage8. Neither runs 'out of 
> the box' under MacRuby Beta.5(2). There are various problems with the Pointer 
> support having evolved (I think), e.g.: errors like "Pointer of type `i', got 
> `l'" - I'm working to correct these and see if I can make the code function 
> again.
> 
> It would be great if we could assemble a web page that documents some of the 
> required knowledge on MAcRuby Pointers for OpenGL.
> 
> regards,  Jonathan
> 
> 
> On 22 Jan 2010, at 16:06, John Shea wrote:
> 
>> 
>> 
>> Thank you again for offering the additional resources. It would be great if 
>> you wanted to add them to your idisc.
>> sure.
>> 
>> 
>> 
>> I did find a copy of your excellent presentation "Building Games with 
>> MacRuby and OpenGL", I must work through the slides again. Did you consider 
>> sharing your game tools? The presentation would make a very useful basis for 
>> a web tutorial on the MacRuby/openGL topic.
>> As far as tools are concerned the only one that ended up being useful in the 
>> end was canning particle effects, so you run the explosion, fireworks or 
>> whatever and then record a series of images, which you can use for animation 
>> later. With IcePhage however it was all on the fly particle effects - canned 
>> animation was not necessary - it could do with some optimisation (both in 
>> look and efficiency) - and macruby speed increases have probably have 
>> improved performance.
>> 
>> Is that what you meant by tools?
>> 
>> The only other software (sans MacRuby) I used was XCode, TextMate and for 3D 
>> experiments Cheetah 3D, some Illustrator & Ria for drawing, graphic 
>> converter to clean up the PNGs.
>> 
>> Let me know if you meant something else regarding tools.
>> 
>> Cheers,
>> 
>> J
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> Like you, I'm new to both openGL and MacRuby - my interest is in 
>> visualisations rather than games. Right now I'm just greatfull that folks 
>> like you are willing to share their hard earned skills.
>> 
>> Best wishes, Jonathan
>> 
>> jonathan 'at' waddilove.net
>> 
>> 
>> On 22 Jan 2010, at 09:28, John Shea wrote:
>> 
>>> Jonathan,
>>> 
>>> I made some 

[MacRuby-devel] MR Examples was: OpenGL/GLUT Bridgesupport

2010-01-24 Thread John Shea
yes, agreed as far as tutorials are concerned.

Regarding example/sample code i think we have a few issues.

i) Laurent and the core team are too busy to do the mundane task of checking 
example code,
ii) because the oficial MacRuby example code is an apple distribution it needs 
to be always working and best practice.
iii) changing versions of MacRuby can "age" working examples quickly

I think the solutions to these problems are:

 i) delegate someone to manage a separate example area, not part of the 
distribution - i vote for you Jordan ;-), 

ii) & iii) the example area is by definition a work area - under constant 
change / review etc  - so it does not matter how bad people think their working 
code is:

 (and because people are learning, the code can be ((certainly in my case)) 
rather Frankestein-ien )

- it can be posted to the site, and the community could clean / refactor, add 
tests etc. 

The core team can cherry pick the best as needed.

Currently everyone posts their code to a multiple of places, it is often not 
peer reviewed, and often forgotten 2 weeks later.

what do you think?
J


On Jan 23, 2010, at 11:41 PM, Jordan K. Hubbard wrote:

> Why stop there?   As we start to accumulate a growing collection of code 
> samples and "conventional wisdom" about how to solve certain types of 
> problems, it would be nice to get all of that information properly 
> categorized and up on the project web site (specifically somewhere linked 
> from https://www.macruby.org/documentation.html).  It would nicely compliment 
> all the various tutorials and screencasts already there, most of which tend 
> to give the reader a basic intro to MacRuby ("Here's how to build your first 
> Cocoa app in IB!") and then leave all the really hairy stuff which follows as 
> an exercise for the reader. :-)
> 
> - Jordan
> 
> On Jan 23, 2010, at 6:19 AM, Jonathan Waddilove wrote:
> 
>> It would be great if we could assemble a web page that documents some of the 
>> required knowledge on MAcRuby Pointers for OpenGL.
> ___
> 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] Blogs posts and another links in macruby website

2010-04-24 Thread John Shea
Hi Daniel,
the last one on the list (mine) has code which is getting very old and
crusty now - developed on 0.4 - I am not sure the code is all that useful
anymore - in fact i was just about to remove the examples.

Feel free to take copies of course (very soon) - but I a doubt there is too
much of interest that cannot be found elsewhere in a much more modern (and
in much nicer ruby/macruby idiomatic) form.
Cheers,
J



On Sun, Apr 25, 2010 at 2:02 AM, Daniel Lopes wrote:

> I just forked macruby website and want to add some new links in
> documentation page. The problem is the website doesn't have a space for
> that.
> I'm thinking in create a new session inside
> http://localhost:4331/documentation.html with the title "Misc" or "Another
> Resources". My idea is share this links for now:
>
> Objective-C for Ruby developers, un not-so-petit interlude 
> (1/2)
> Creating our very first Mac application with Ruby, how 
> exciting!
> A gentle introduction to 
> MacRuby
> http://public.me.com/johnmshea
>
> And keep adding new posts. What do you think?
>
> ___
> 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