[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NSSelectorFromString and undefined selectors
From: |
Stefan Urbanek |
Subject: |
NSSelectorFromString and undefined selectors |
Date: |
Sat, 23 Feb 2002 08:52:41 +0100 |
Hi,
I have following problem. This used to work, but it does not anymore with
current gnustep on CVS.(StepTalk is broken)
I have:
MyClass *obj = /* some object with forwarding in forwardInvocation: */;
SEL sel;
This code is OK:
/* get an existing selector */
sel = NSSelectorFromString(@"count");
/* this is fine, because selector 'count' is defined in NSArray */
[obj performSelector:sel];
But something wrong is here:
/* NSSelectorFromString used to return 0 when there was no selector
defined */
sel = NSSelectorFromString(@"myMethodInScript");
/* selector is never more null here! */
if(sel)
{
/* we got an exception here */
[obj performSelector:sel];
}
else
{
/* but I want to register undefined selector to prevent
that exception ... */
NSLog(@"No selector - registering");
sel = sel_register_typed_name("myMethodInScript", "@8@0:4");
}
/* ... and use it here */
[obj performSelector:sel];
In NSObjCRuntime.h I read:
/**
* Return a selector matching the specified name, or nil if no name is
* supplied. The returned selector could be any one with the name.<br />
* If no selector already exists, creates one.
*/
FOUNDATION_STATIC_INLINE SEL
GSSelectorFromName(const char *name)
...
But Cocoa documentation says:
NSSelectorFromString
This function obtains a selector by name.
SEL NSSelectorFromString(NSString *aSelectorName)
Returns the selector named by aSelectorName, or zero if none by this name
exists.
So, the gnustep code is now returning selector in any case, if it was defined
or not. But it should return ONLY when it IS defined. I think, that Cocoa
behavior is correct, because if there is not such selector defined, I can
register it by my self. And I want to register it by my self, because I need
to register also types for that selector. This is needed to implement 'script
methods' in StepTalk (see Source/STObjCRuntime.m and
Languages/Smalltalk/STCompiledObject.m and STCompiledScript.m).
Thanks,
Stefan
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- NSSelectorFromString and undefined selectors,
Stefan Urbanek <=