static int get(Interp interp, TclObject tobj, String table[], String msg, int flags) throws TclException
If a match is made, the index of the matching entry is returned, and the internal representation of tobj is modified to hold the address of table and the index of the matching entry. If TclIndex.get() is invoked again with the same tobj and table arguments (e.g. during a re-invocation of a Tcl command), it returns the matching index immediately without having to redo the lookup operation.
If there is no matching entry, a TclException is thrown, and an error message is left in interp's result if interp isn't NULL. The msg argument is included in the error message to indicate what kind of data that was being looked up.
static final private String opts[] = { "first", "second", "third" };When a call is made to foo, we use the get method to find out which option was specified in the first argument to the foo command,argv[1]:
int opt = TclIndex.get(interp, argv[1], opts, "option", 0);If argv[1]'s internal string representation is either "second", "sec", or "s" a match is made. However, if argv[1]'s internal string representation is "scd", no match is made, and the get method generates the following error message:
bad option "scd": must be first, second, or third.
Copyright © 1996-1998 Sun Microsystems, Inc. Copyright © 1995-1997 Roger E. Critchlow Jr.