Re: Introspecting the current method

2010-04-19 Thread Jean-Daniel Dupas
Le 19 avr. 2010 à 20:54, Greg Parker a écrit : > On Apr 18, 2010, at 7:01 PM, Ken Thomases wrote: >> On Apr 18, 2010, at 7:14 PM, Dave DeLong wrote: >>> If I'm inside a method, is there a way to know at runtime whether that >>> method is a class or an instance method? >> >> Keep in mind that cl

Re: Introspecting the current method

2010-04-19 Thread Greg Parker
On Apr 18, 2010, at 7:01 PM, Ken Thomases wrote: > On Apr 18, 2010, at 7:14 PM, Dave DeLong wrote: >> If I'm inside a method, is there a way to know at runtime whether that >> method is a class or an instance method? > > Keep in mind that class methods are just instance methods, where the instanc

Re: Introspecting the current method

2010-04-19 Thread Greg Parker
On Apr 19, 2010, at 7:09 AM, Michael Ash wrote: > On Mon, Apr 19, 2010 at 3:27 AM, Jean-Daniel Dupas > wrote: >> >> Le 19 avr. 2010 à 04:21, Michael Ash a écrit : >>> On Sun, Apr 18, 2010 at 10:15 PM, Dave DeLong wrote: Yes, code should obviously be written with this knowledge in mind. The

Re: Introspecting the current method

2010-04-19 Thread Roy Lovejoy
Take a look at __PRETTY_FUNCTION__ - it includes the C++ class or the Obj-C class depending.. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-d

Re: Introspecting the current method

2010-04-19 Thread Michael Ash
On Mon, Apr 19, 2010 at 3:27 AM, Jean-Daniel Dupas wrote: > > Le 19 avr. 2010 à 04:21, Michael Ash a écrit : > >> On Sun, Apr 18, 2010 at 10:15 PM, Dave DeLong wrote: >>> Yes, code should obviously be written with this knowledge in mind.  The use >>> case I have for it is for macros.  I like to

Re: Introspecting the current method

2010-04-19 Thread Jack Nutting
On Mon, Apr 19, 2010 at 9:27 AM, Jean-Daniel Dupas wrote: > It is fine for most cases, but __func__ is defined at compile time, and so, > does not log the real type of the instance (if this is a subclass). > Hmmm, that's too bad. Seems to be the case for __FUNCTION__ and __PRETTY_FUNCTION__ as

Re: Introspecting the current method

2010-04-19 Thread Jean-Daniel Dupas
Le 19 avr. 2010 à 04:21, Michael Ash a écrit : > On Sun, Apr 18, 2010 at 10:15 PM, Dave DeLong wrote: >> Yes, code should obviously be written with this knowledge in mind. The use >> case I have for it is for macros. I like to use a debugging macro like the >> following to ensure that method

Re: Introspecting the current method

2010-04-18 Thread Ken Thomases
On Apr 18, 2010, at 9:26 PM, Dave DeLong wrote: > That's amazing! Is there some sort of coherent list of magic identifiers > somewhere? http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html Cheers, Ken ___

Re: Introspecting the current method

2010-04-18 Thread Dave DeLong
Actually, I just found it! http://developer.apple.com/mac/library/documentation/DeveloperTools/gcc-4.0.1/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros This will certainly suit my purposes what I was needing. However, the check of [self class] == self is still really useful. Th

Re: Introspecting the current method

2010-04-18 Thread Ken Thomases
On Apr 18, 2010, at 9:21 PM, Michael Ash wrote: > On Sun, Apr 18, 2010 at 10:15 PM, Dave DeLong wrote: >> Yes, code should obviously be written with this knowledge in mind. The use >> case I have for it is for macros. I like to use a debugging macro like the >> following to ensure that method

Re: Introspecting the current method

2010-04-18 Thread Dave DeLong
That's amazing! Is there some sort of coherent list of magic identifiers somewhere? Dave On Apr 18, 2010, at 8:21 PM, Michael Ash wrote: > The magic __func__ identifier produces a C string which I believe, in > an ObjC method, has exactly the format you're looking for. smime.p7s Description:

Re: Introspecting the current method

2010-04-18 Thread Michael Ash
On Sun, Apr 18, 2010 at 10:15 PM, Dave DeLong wrote: > Yes, code should obviously be written with this knowledge in mind.  The use > case I have for it is for macros.  I like to use a debugging macro like the > following to ensure that methods are getting called (without having to break > execu

Re: Introspecting the current method

2010-04-18 Thread Dave DeLong
Yes, code should obviously be written with this knowledge in mind. The use case I have for it is for macros. I like to use a debugging macro like the following to ensure that methods are getting called (without having to break execution to stop at a breakpoint): #define LogMethod NSLog(@"-[%@

Re: Introspecting the current method

2010-04-18 Thread Ken Thomases
On Apr 18, 2010, at 7:14 PM, Dave DeLong wrote: > If I'm inside a method, is there a way to know at runtime whether that method > is a class or an instance method? Keep in mind that class methods are just instance methods, where the instance is the class object. (The class object being an inst

Re: Introspecting the current method

2010-04-18 Thread Dave Keck
At runtime, I would use: #define classMethod() (self == [self class]) And just for fun, at compile-time: GCC: #define classMethod() (__builtin_choose_expr( \ __builtin_types_compatible_p(__typeof__(self), \ __typeof__(id)), YES, NO)) LLVM: #define classMeth

Re: Introspecting the current method

2010-04-18 Thread Sherm Pendley
On Sun, Apr 18, 2010 at 8:21 PM, Graham Cox wrote: > > On 19/04/2010, at 10:14 AM, Dave DeLong wrote: > >> If I'm inside a method, is there a way to know at runtime whether that >> method is a class or an instance method?  Currently the only way I though of >> to do this is to see if "self" is a

Re: Introspecting the current method

2010-04-18 Thread Graham Cox
On 19/04/2010, at 10:14 AM, Dave DeLong wrote: > If I'm inside a method, is there a way to know at runtime whether that method > is a class or an instance method? Currently the only way I though of to do > this is to see if "self" is a Class object or not, but I was wondering if > there's a m

Introspecting the current method

2010-04-18 Thread Dave DeLong
Hi everyone, I was just writing some code and asked myself a question that I don't know the answer to, and a quick look in the documentation didn't reveal anything promising. If I'm inside a method, is there a way to know at runtime whether that method is a class or an instance method? Curren