🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #1664

Re: Code to show all methods an object responds to.

#1664
From: Gregory H. Anderson
Date: Tue, 29 Sep 1992 15:51
42 lines
2030 bytes
In article <1992Sep26.033132.245@nugget.rmNUG.ORG> timothy@eddie.rmNUG.org  
writes:
> I saw some code in a post a little while back that would list all the  
> methods an object would respond to. I've searched and searched to no  
> avail. Could someone point me in the right direction or send me the  
> post.

Here is a small code sample to list the names and arguments of all methods  
an object can respond to. Note that method_name is a selector, which is  
then mapped to the ASCII name with sel_getName. method_types has a complex  
encoding mechanism that includes the return value type, followed by a list  
of argument coding characters and distances from the stack pointer. It's  
better to use the runtime method_xxx() calls to get this information.
 
============================ clip 'n' save =========================

- printMethodListFor:sender
  {
  Class classInfo = [sender class];
  int i;

  while (classInfo)
    {
    if (classInfo->methods != NULL) 
      {
      for (i = 0; i < classInfo->methods->method_count; i++)
        printf("%s %s\n", 
          sel_getName(classInfo->methods->method_list[i].method_name),
          classInfo->methods->method_list[i].method_types);
       }
      classInfo = classInfo->super_class;
    }
    return self;
  }

============================ clip 'n' save =========================

--
Gregory H. Anderson          | "We're very tolerant around here,
Benevolent Dictator-for-Life |  being only amateurs ourselves."
Anderson Financial Systems   | - Tortoise (Godel, Escher, Bach)
greg@afs.com  (Nextmail OK)  | 
Technical Details
Message-ID: <1992Sep29.155125.7983@afs.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!usc!rpi!psinntp!psinntp!afs!greg
References: <1992Sep26.033132.245@nugget.rmNUG.ORG>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!usc!rpi!psinntp!psinntp!afs!greg
From: greg@afs.com (Gregory H. Anderson)
Subject: Re: Code to show all methods an object responds to.
Message-ID: <1992Sep29.155125.7983@afs.com>
Sender: greg@afs.com
Reply-To: greg@afs.com
References: <1992Sep26.033132.245@nugget.rmNUG.ORG>
Date: Tue, 29 Sep 1992 15:51:25 GMT
Lines: 42