Syntax errors, undeclared variables
Syntax errors, undeclared variables
- Subject: Syntax errors, undeclared variables
- From: Kevin Walzer <email@hidden>
- Date: Fri, 06 Feb 2009 21:51:32 -0500
- Organization: WordTech Communications LLC
I'm trying to build a small extension to the Tcl scripting language that
hooks into Cocoa/Objective-C. The idea is to change an application's
dock icon with a call to [NS App setApplicationIconImage]. However, when
I try to compile my code, I get various errors, such as:
cocoadock.m:11: error: syntax error before ‘(’ token
cocoadock.m: In function ‘-[CocoaDock switchIcon]’:
cocoadock.m:26: error: syntax error before ‘(’ token
cocoadock.m:28: error: ‘objc’ undeclared (first use in this function)
cocoadock.m:28: error: (Each undeclared identifier is reported only once
cocoadock.m:28: error: for each function it appears in.)
cocoadock.m:29: error: ‘ip’ undeclared (first use in this function)
cocoadock.m:29: error: ‘objv’ undeclared (first use in this function)
cocoadock.m:38: warning: initialization from incompatible pointer type
I'm not sure what is causing these errors. Line 11 is set up like this:
-(int)switchIcon (ClientData cd, Tcl_ip *ip, int objc, Tcl_Obj *objv[]);
The ClientData, Tcl_ip, and Tcl_Obj parameters are from the Tcl C API
and are defined in the appropriate header file. It's not clear to me why
the variables cd , *ip, etc. are not recognized. It is also not clear to
me where the syntax error in line 11 might be.
Can anyone point me in the right direction? The entire code snippet is
below. I'm running Leopard 10.5.6.
/* cocoadock.m -- compile with these flags:
gcc -o cocoadock.o cocoadock.m -framework Tcl -framework Cocoa
*/
#import <tcl.h>
#import <Cocoa/Cocoa.h>
@interface CocoaDock: NSApplication {
NSImage *appIcon;
NSImage *newIcon;
}
-(id) init;
-(int)switchIcon (ClientData cd, Tcl_ip *ip, int objc, Tcl_Obj *objv[]);
@end
@implementation CocoaDock;
-(id) init {
self = [super init];
[NSApplication sharedApplication];
return self;
}
// Tcl command to set the dock icon.
-(int) switchIcon (ClientData cd, Tcl_ip *ip, int objc, Tcl_Obj *objv[]) {
if(objc != 2) {
Tcl_WrongNumArgs(ip, 1, objv, "iconPath");
return TCL_ERROR;
}
//first, get the original icon
appIcon = [NSImage imageNamed: @"NSApplicationIcon"];
//path to new icon
NSString *iconPath = Tcl_GetStringFromObj(objv[1], nil);
//convert file path to URL
NSURL *iconURL = [NSURL fileURLWithPath: iconPath];
//create image from URL
newIcon = [[NSImage alloc] initWithContentsOfURL: iconURL];
if(newIcon == nil) {
Tcl_AppendResult (ip, "couldn't create icon image from path",
(char *) nil);
return TCL_ERROR;
}
//set the new image
[NSApp setApplicationIconImage: newIcon];
//release the memory
[newIcon release];
return TCL_OK;
}
@end
--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden