discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSInvocation problems


From: PUYDT Julien
Subject: NSInvocation problems
Date: Sat, 23 Aug 2003 15:32:49 +0200

Hi,

I'm having problem using that class:
* I was unable to use either the NS_MESSAGE or the NS_INVOCATION macro
(it segfaults);
* now, I've problems to use an invocation with arguments. I made a small
test program to show what happens, ie: nothing, not even an error
message, a warning or whatever...

Is it a bug, or is it me doing something wrong? I'm new to both
Objective C and GNUstep, so it is possible...

Snark on #gnustep

PS: the sources of the test:
#include <Foundation/Foundation.h>

@interface Helper: NSObject
+(void)withargs: (int)unused;
+(void)noarg;
@end

@implementation Helper
+(void)withargs: (int)unused
{
  NSLog(@"invocation of withargs");
}
+(void)noarg
{
  NSLog(@"invocation of noarg");
}
@end

int main(int argc, const char *argv[])
{
  NSInvocation *invoc;
  SEL sel;
  int anInt = 2;

  NSAutoreleasePool *pool;
  pool = [NSAutoreleasePool new];

  // first the noarg method
  sel = @selector(noarg);
  invoc = [NSInvocation invocationWithMethodSignature: 
                          [Helper methodSignatureForSelector: sel]];
  [invoc retainArguments];
  [invoc setTarget: [Helper class]];
  [invoc setSelector: sel];
  [invoc invoke];

  // second the witharg method
  sel = @selector(withargs);
  invoc = [NSInvocation invocationWithMethodSignature: 
                          [Helper methodSignatureForSelector: sel]];
  [invoc retainArguments];
  [invoc setTarget: [Helper class]];
  [invoc setSelector: sel];
  [invoc setArgument: &anInt atIndex: 2];
  [invoc invoke];
  
  RELEASE(pool);
  return 0;
}






reply via email to

[Prev in Thread] Current Thread [Next in Thread]