01: /*
02: * ItclExtension.java
03: *
04: * Load Itcl package commands/
05: *
06: * Copyright (c) 2004 Mo DeJong
07: *
08: * See the file "license.itcl" for information on usage and
09: * redistribution of this file, and for a DISCLAIMER OF ALL
10: * WARRANTIES.
11: *
12: * RCS: @(#) $Id: ItclExtension.java,v 1.1 2005/09/11 20:56:57 mdejong Exp $
13: *
14: */
15:
16: package itcl.lang;
17:
18: import tcl.lang.*;
19:
20: public class ItclExtension extends Extension implements Command {
21: /*
22: * Called via [java::load itcl.lang.ItclExtension]
23: * or from the jaclloaditcl command implemented below.
24: */
25:
26: public void init(Interp interp) throws TclException {
27: boolean issafe = false;
28:
29: TclObject result;
30: interp.eval("interp issafe {}");
31: result = interp.getResult();
32: issafe = TclBoolean.get(interp, result);
33:
34: if (issafe) {
35: Cmds.SafeInit(interp);
36: } else {
37: Cmds.Init(interp);
38: }
39: }
40:
41: /*
42: * Invoked when [package require Itcl] is run from Tcl.
43: * This method is needed so that Itcl can be loaded
44: * without having first loaded the Java package.
45: */
46:
47: public void cmdProc(Interp interp, // Current interpreter.
48: TclObject[] objv) // Arguments to "jaclloaditcl" command.
49: throws TclException {
50: // This method takes no arguments
51: if (objv.length != 1) {
52: throw new TclNumArgsException(interp, 1, objv, "");
53: }
54:
55: this .init(interp);
56:
57: interp.deleteCommand(objv[0].toString());
58: }
59: }
|