|
From: Christian H. <chr...@gm...> - 2005-07-20 23:43:51
|
Hi again,
now that the installation finally succeeded, the real problems begin...
I wrote a small application with a "Quit" button. Before the
application displays that it quits, I want it to perform some fancy
action: call the dummy method "dummy" on itself. (Ok, this is just a
simplified version of what I really want...)
To make it more interesting, it uses the "performSelectorWithObject"
method on itself. When I do this, my application crashes.
In Objective-C it looks like this (and it works):
- (IBAction)quit:(id)sender
{
[self performSelector: @selector(dummy:) withObject: self];
[actionLabel setStringValue: [NSString stringWithCString:
"Quit!" encoding: NSMacOSRomanStringEncoding]];
}
- (void)dummy:(NSObject*)ignored
{
}
In Haskell, I started like this:
I declared a selector for my dummy in my Selectors.hs:
$(declareSelector "dummy:" [t| forall a. NSObject a -> IO ()|])
Then I added an instance method:
$(exportClass [...] InstanceMethod Selectors.info_dummy])
inet_dummy _ self = return ()
inet_quit _ self =
self # performSelectorWithObject (getSelectorForName "dummy:") self
-- self # inet_dummy self <-- that works, but is not what I want!
self #. _actionLabel >>= setStringValue (toNSString ("Quit!"))
-- replacing this line with just a "return ()" works as well!!!
Now, the selector is found ((self # respondsToSelector
(getSelectorForName "dummy:")) returns true), but when I try to
perform the selector, and change the label text afterwards, the
application crashes. Am I doing something wrong?
(Remark: I did not use the -O compiler option.)
By the way, is there a way to get MVar concurrency working together
with HOC? Can I use MVars just like that (after telling Cocoa to run
thread-safe)? Do I have to use POSIX threads?
Regards,
Chris
|