B
Benjohn Barnes
Hello,
I've been inspired by reading:
http://www.rubycocoa.com/mastering-cocoa-with-ruby/1
But I don't really want to have to build an application that's a ruby
console.
I'd like to be able to fire up the NSApplication's run loop from
within a new NSThread. My thinking is that if I do this from IRB, I
can then continue to use the original thread. I'll have a proper
application run loop that's able to respond to events, but I'll also
be able to continue developing code live within irb. Obviously, I'll
have to be very careful in interacting with the main application, but
I think it ought to be possible with:
performSelectorOnMainThread_withObject_waitUntilDone.
I suspect I'm being naive in the extreme to even expect this to
work. But as an optimist, I thought I'd see what happened if I tried.
Here's my code:
####
class ApplicationRunner < OSX::NSObject
def run
pool = OSX::NSAutoreleasePool.alloc.init
NSApplication.sharedApplication.run
pool.release
end
end
runner = ApplicationRunner.alloc.init
OSX::NSThread.detachNewThreadSelector_toTarget_withObjectexit,
runner, nil)
####
And here's some output from it:
Which isn't too hopeful.
Is this just a silly idea? Can anyone suggest what I'm doing wrong
(no doubt, quite a lot of things), or a better approach to this?
Cheers,
Benjohn
I've been inspired by reading:
http://www.rubycocoa.com/mastering-cocoa-with-ruby/1
But I don't really want to have to build an application that's a ruby
console.
I'd like to be able to fire up the NSApplication's run loop from
within a new NSThread. My thinking is that if I do this from IRB, I
can then continue to use the original thread. I'll have a proper
application run loop that's able to respond to events, but I'll also
be able to continue developing code live within irb. Obviously, I'll
have to be very careful in interacting with the main application, but
I think it ought to be possible with:
performSelectorOnMainThread_withObject_waitUntilDone.
I suspect I'm being naive in the extreme to even expect this to
work. But as an optimist, I thought I'd see what happened if I tried.
Here's my code:
####
class ApplicationRunner < OSX::NSObject
def run
pool = OSX::NSAutoreleasePool.alloc.init
NSApplication.sharedApplication.run
pool.release
end
end
runner = ApplicationRunner.alloc.init
OSX::NSThread.detachNewThreadSelector_toTarget_withObjectexit,
runner, nil)
####
And here's some output from it:
2007-01-03 23:30:42.204 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54d020 of class NSInvocation autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.205 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54e7d0 of class NSCFDictionary autoreleased with no pool
in place - just leaking
2007-01-03 23:30:42.205 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54e200 of class RBObject autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.206 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54df40 of class NSCFString autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.206 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x3060e0 of class NSCFString autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.207 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54df60 of class NSCFArray autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.207 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54e8b0 of class NSCFString autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.207 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54e9b0 of class NSCFString autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.208 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54e920 of class NSCFString autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.208 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54df70 of class NSCFString autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.208 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54ea30 of class NSCFString autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.208 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54f670 of class NSCFString autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.209 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54f6f0 of class NSCFString autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.209 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54df90 of class NSCFString autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.209 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54f7d0 of class NSCFString autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.210 irb[4904] *** _NSAutoreleaseNoPool():
Object 0x54f7b0 of class NSException autoreleased with no pool in
place - just leaking
2007-01-03 23:30:42.210 irb[4904] *** Uncaught exception:
<RBException_SystemExit> exit
Which isn't too hopeful.
Is this just a silly idea? Can anyone suggest what I'm doing wrong
(no doubt, quite a lot of things), or a better approach to this?
Cheers,
Benjohn