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

  Other Tcl Procedures

cdefine ?flags? cstuff
cdef ?flags? cstuff

Parses arbitrary C/ObjC syntax text.
You can use this to define types, global variables, functions, classes, protocols, and even implement methods.

Flags:
-prefix pfx
    Prefix pfx will be used for resolving global symbol names.  This is useful under Windows.
-out
Return what's parsed in the form appropriate to be included in a .cfun file.
-no_def
Just parse the file, don't define anything.

Example:

 tcl% cdef -out { 
 %--> extern double sin(double); 
 %--> 
 %--> @protocol MyProtocol 
 %--> - (void)aMethod; 
 %--> @end 
 %--> 
 %--> @interface NSObject(Add_A_Method) 
 %--> - (NSString*)sayHello; 
 %--> /* ObjTcl: 
 %-->    return "$self sez hello to you" 
 %--> */ 
 %--> @end 
 %--> } 
 sin <"?"d"?"d> 
 #@protocol MyProtocol 
 #@category NSObject(Add_A_Method) 
 tcl% sin 1 
 0.841470984808 
 tcl% unparse [protocol MyProtocol] 
 @protocol MyProtocol 
 // Implemented by: no one 
 // Class methods: none 
 // Instance methods 
 - (void)aMethod; 
 @end 
 tcl% $NSApp sayHello 
 @TTApplication@98df0 sez hello to you 

Note: The cdef facility is not a full-fledged C compiler: C function bodies, and ObjC method bodies are not parsed.

Note: Mixing multiple-language method implementations in a single category definition is not yet fully supported.

cinclude ?flags? file

Parses C/ObjC syntax text from file.

Flags are as in cdef, plus:
-cpp ppflags
this flag is specified, file is passed through preprocessor.  Use -traditional-cpp to disable GNU preprocessor parsing.

Example:

 tcl% cinclude -cpp {} /usr/include/ansi/stdio.h 
 tcl% set f [fopen "/tmp/test" "w"] 
 ^{_iobuf}@0x50c248c 
 tcl% fprintf $f "Hello World!\n" 
 0 
 tcl% fclose $f 
 0 
 tcl% exec cat /tmp/test 
 Hello World! 
msg_send obj selector args...

Invokes obj's method selector with args.

msg_send_super class obj selector args...

Invokes obj's method selector in the specified class with args.

msg_send_ex class idx obj selector args...

This is the most general form of the msg_send.  It invokes obj's method selector in the specified class and category indicated by idx.

The idx argument has the following meaning:

tt val

Returns 1 if value val is "non-zero", 0 otherwise.  "Zero" values are [NULL], [nil], "nil", "0x0", {}, 0, etc.  This command provides a convenient way to test the return value of a method invocation.  E.g.:

if [tt [$obj msg: $sender]] { ... }

ivarset obj ?ivar ?value??

If ivar is specified, and value is not, ivarset returns the value of object obj's instance variable ivar.  If value is specified, then set the value of obj's instance variable ivar to value.  In neigher ivar nor value is specified, returns a list of all instance variables.

 tcl% ivarset $NSApp 
 isa _nextResponder _currentEvent _windowList _keyWindow _mainWindow _delegate _hiddenList _hiddenCount _context _appListener _appSpeaker _unusedApp _running _appFlags _mainMenu _appIcon _nameTable _reservedApplication1 _reservedApplication2 
 tcl% ivarset $NSApp isa 
 TTApplication 
xvarset obj ?name ?value??

In addition to instance variables, Objective-Everything objects can have any number of attribute values associated with it.  Attribute values are of type "id".  If name is specified, and value is not specified, xvarset returns the value of object obj's attribute name.  If value is specified, then set the value of obj's attribute name to value.

 tcl% xvarset $NSApp 
 tcl% xvarset $NSApp attr 
 object <TTApplication:0x98df0> has no key "attr" 
 tcl% xvarset $NSApp attr [NSObject object] 
 @NSObject@ad1b0 
 tcl% xvarset $NSApp attr 
 @NSObject@ad1b0 
 tcl% xvarset $NSApp 
 attr 
class_rename class newname

Renames class to newname.  Use this with caution!

dyload module ?module...?

Dynamically loads specified modules.  To build a module from files a.m, b.m, and c.m so that it can be loaded:

NeXT:

 compile each file into .o, then: 
 cc -bundle -undefined suppress -o abc.so a.o b.o c.o 

GNU:

 compile each file: 
 gcc -fpic -FPIC -c a.m 
...

then link:

 gcc -nostdlib -nostartfiles -o abc.so a.o b.o c.o 

To load abc.so:

 objtcl::dyload abc.so 
lookup objname

If objname is a valid object name, returns object the object corresponding to objname.  Otherwise, an error is raised.

 tcl% lookup nil 
 nil 
 tcl% lookup NSObject 
 NSObject 
 tcl% lookup 0x46f38 
 @NSObject@46f38 
 tcl% lookup [addrof NSObject] 
 NSObject 
 tcl% set x [NSObject object] 
 @NSObject@46f38 
 tcl% lookup @NSObject@46f38 
 @NSObject@46f38 
 tcl% lookup @NSObject@1234 
 object 0x1234 is not registered 
 tcl% lookup "<NSObject: 0x46f38>" 
 @NSObject@46f38 
chr number

Returns a 1-element string that corresponds to ASCII character code number.  E.g., chr 65 returns A.

ord str

Returns the ASCII code number of the first character of string str.  E.g., ord A returns 65.

iputs ?-nonewline? ?channelId? string

Replacement for the default Tcl puts which prints string into the current interactor, instead of writing it to stdout. If there is no current interactor, the default Tcl puts is used.

gets channelId ?varName?

Replacement for the default Tcl gets which modally reads a line from the current interactor, instead of reading it from stdin.  If there is no current interactor, the default Tcl gets is used.

@ str

Returns: [NSString stringWithCString: str]

@arr list

Converts Tcl list list to an NSMutableArray.

@dict list

Convert Tcl list list to an NSMutableDictionary.  List must have an even number of elements.  Even elements are keys, odd elements are values.

* obj

Returns object's description as a plain Tcl string value.  It obj is not an object, then * just returns its argument.

** obj

Applies "extended-conversion" to obj.  NSArrays and NSDictionaries are converted to Tcl lists.

map var obj ?enumerator? body
foreach@ var obj ?enumerator? body

Iterates variable over the elements of obj enumerated by enumerator.  In each iteration, body is executed.  The default enumerator is objectEnumerator.

AppKit Support

appkit::load

Loads the AppKit and ObjAppKit frameworks and returns 1 if successful.

appkit::run ?-nib path? ?-class class? ?command?

Runs the AppKit main event loop.  Loads AppKit if needed.  The -nib flag can be used to specify the main nib file.  The -class flag can be used to specify the application class.  If command is specified, it is executed as soon as the main event loop starts running.

appkit::after command ?delay?

Asynchronously executes command.  If the delay argument is specified, command is executed after delay seconds.

Debugging Support

debug ?-now? ?bool?

If bool is 1, then the Tcl debugger is activated.  If -now flag is given, then the debugger is immediately invoked.  If bool is 0, then the debugger is deactivated.  If no arguments are given, this procedure returns 1 if the debugger is currently active, or 0 if not.

attach_gdb ?full_executable_path?

Attaches GDB to this process.  This procedure tries its best to guess the full executable path of this process.  This file is used by GDB to read symbols.  You can explicitly specify this path.

Global Variables

$interp

Represents the interpreter object.

$NSApp, $NSArgc, $NSArgv, etc.

Linked C globals.  See $objtcl_library/objtcl.tcl.


[previous][contents][next]