Objective-Everything Release 5.  Copyright ©1994-1998 by TipTop Software, Inc.  All Rights Reserved.

  Introspection

Objective-Tcl introspection facility allows you to obtain various information about the runtime system.

All Objective-Tcl procedures live in the objtcl:: namespace.  This namespace is, by default, imported into global namespace so that you normally do not have to prefix ObjTcl commands with objtcl::

Unparse

Unparse extracts the class and protocol information from the runtime and returns it in the familiar ObjC-style syntax form.

unparse ?-decompile? ?-verbose? object

If the object is a class, that class is unparsed.
If the object is an instance, its class is unparsed.
If the object is a protocol, the protocol is unparsed

If you specify the -decompile flag, method implementation bodies for Objective-Everything-defined methods will be included.
If you specify the -verbose flag, type names are fully expanded.

Example:

 tcl% unparse NSObject 
 @interface NSObject : Nil <NSObject> 
 // Subclasses: NSLayoutHole NSCustomResource NSStorage 
 ... 
 { 
   Class isa; 
 } 
 // Class methods 
 ... 
 // Instance methods 
 ... 
 @end 
 tcl% unparse [protocol NSObject] 
 @protocol NSObject 
 // Implemented by: NSObject NSProxy 
 // Class methods: none 
 // Instance methods 
 - (id)description; 
 ... 
 @end 
 tcl% class MyObject NSObject { 
 %-->   NSString *aString; 
 %-->   id anObject; 
 %-->   char *aCString; 
 %-->   NSRect aRect; 
 %--> } { 
 %-->   method -(void)dealloc { 
 %-->     set aString [nil]   ; # release aString 
 %-->     set anObject [nil]  ; # release anObject 
 %-->     set aCString [NULL] ; # free aCString 
 %-->     super dealloc 
 %-->   } 
 %--> 
 %-->   method -(void)setStringValue:(NSString*)s { 
 %-->     puts "$self $_cmd $s" 
 %-->     set aString $s 
 %-->   } 
 %--> 
 %-->   method -(NSString*)stringValue { 
 %-->     puts "$self $_cmd" 
 %-->     return $aString 
 %-->   } 
 %--> 
 %-->   # etc. 
 %--> } 
 MyObject 
 tcl% unparse MyObject 
 @interface MyObject : NSObject 
 // Subclasses: None 
 { 
   NSString* aString; 
   id anObject; 
   STR aCString; 
   NSRect aRect; 
 }

 // Class methods 

 // Instance methods 
 // ------------------------------- 1 ------------------------------- 
 - (id)stringValue; 
 - (void)setStringValue:(id)s; 
 - (void)dealloc; 
 @end 

 tcl% unparse -decomp MyObject 
 @interface MyObject : NSObject 
 // Subclasses: None 
 { 
   NSString* aString; 
   id anObject; 
   STR aCString; 
   NSRect aRect; 
 } 

 // Class methods

 // Instance methods 
 // ------------------------------- 1 ------------------------------- 
 - (id)stringValue; 
 /* ObjTcl: 
    puts "$self $_cmd" 
    return $aString 
 */ 

 - (void)setStringValue:(id)s; 
 /* ObjTcl: 
     puts "$self $_cmd $s" 
     set aString $s 
 */

 - (void)dealloc; 
 /* ObjTcl: 
     set aString [nil]   ; # release aString 
     set anObject [nil]  ; # release anObject 
     set aCString [NULL] ; # free aCString 
     super dealloc 
 */

 @end 

Note that the result of unparse can be used as a header file for compiled ObjC.

Info

All the introspection functionality is available via the info command.

Note: The info command is not exported from the objtcl:: namespace because that would conflict with the standard Tcl info command.  Hence, you invoke info as objtcl::info.  Alternatively, you can use xinfo, which is exported from the objtcl:: namespace


info version

Returns the ObjTcl version number.

info library

Returns ObjTcl library path.

info arch

Returns architecture name.

info os

Returns OS name.

info osversion

Returns OS version.

info tiptop

Returns TipTop contact information.

info copyright

Returns TipTop copyright information.


info classes ?pattern?

Returns a list of all class names which match the pattern.

Example:

 tcl% objtcl::info classes *Window* 
 NSWindowTemplate NSWindow NSComboBoxWindow 
info protocols ?pattern?

Returns a list of all protocol names known to the Objective-Everything runtime system which match the pattern.

info ids ?pattern?

Returns a list of all objects names registered with the Objective-Everything runtime system which match the pattern.

info types ?pattern?

Returns a list of all type names known to the system which match the pattern.

Example:

 tcl% objtcl::info types *int* 
 uint NSPoint int 
info functions ?pattern?

Returns a list of all function names known to the system which match the pattern.

Example:

 tcl% objtcl::info func *Run*AlertPanel 
 NSRunInformationalAlertPanel NSRunCriticalAlertPanel NSRunAlertPanel 
info globals ?pattern?

Returns a list of all global variable names known to the system which match the pattern.

Example:

 tcl% xinfo glob NSArg* 
 NSArgc NSArgv 
info constants ?pattern?

Returns a list of all constant names known to the system which match the pattern.


info methods ?-all? ?-name? ?-who? ?-decomp? class ?pattern?

Returns a list of all method names in the class which match the pattern.  To obtain method information for a specific instance obj, simply use [obj class] as the class argument.

Flags:
-all
all superclasses are searched as well.
-name
only method selector names, rather than full prototypes is returned.
-who
each element in the list returned consists of a method selector name and a class implementing a selector.
-decomp
method body implementation is returned.

Example:

 tcl% xinfo meth MyObject {*[sS]tring*} 
 - (id)stringValue; 
 - (void)setStringValue:(id)s; 
tcl% xinfo meth -decomp MyObject dealloc 
 - (void)dealloc; 
 /* ObjTcl: 
     set aString [nil]   ; # release aString 
     set anObject [nil]  ; # release anObject 
     set aCString [NULL] ; # free aCString 
     super dealloc 
 */ 
info ivars ?-all? ?-name? ?-who? class ?pattern?

Returns a list of instance variable names declared in the class which match the pattern.

Example:

 tcl% xinfo ivar -all MyObject isa 
 Class isa; 
 tcl% xinfo ivar -all MyObject *String 
 NSString* aString; 
 STR aCString; 

info argnames class selector
info argnames function

Returns a list of argument names for the specified method in class, or function.

info argtypes class selector
info argtypse function

Returns a list of argument types for the specified method in class, or function.

info body class selector

Returns method implementation body.

info language class selector

Returns language name in which the specified method is implemented.

Examples:

 tcl% xinfo argnames MyObject setStringValue: 
 self _cmd s 
 tcl% xinfo argnames NSObject performSelector:withObject: 
 self _cmd a0 a1 
 tcl% xinfo argt MyObject setStringValue: 
 void id SEL id 
 tcl% xinfo body MyObject setStringValue: 

     puts "$self $_cmd $s" 
     set aString $s 

 tcl% xinfo lang MyObject setStringValue: 
 ObjTcl 
 tcl% xinfo lang NSObject performSelector:withObject: 
 ObjC 

info ivtype class ivar

Returns type of the specified instance variable in class.

Examples:

 tcl% xinfo ivtype MyObject aString 
 NSString* aString 

[previous][contents][next]