Exemple #1
0
        internal static Procedure findProc(Interp interp, string procName)
        {
            WrappedCommand cmd;
            WrappedCommand origCmd;

            try
            {
                cmd = NamespaceCmd.findCommand(interp, procName, null, 0);
            }
            catch (TclException e)
            {
                // This should never happen
                throw new TclRuntimeError("unexpected TclException: " + e.Message);
            }

            if (cmd == null)
            {
                return(null);
            }

            origCmd = NamespaceCmd.getOriginalCommand(cmd);
            if (origCmd != null)
            {
                cmd = origCmd;
            }
            if (!(cmd.cmd is Procedure))
            {
                return(null);
            }
            return((Procedure)cmd.cmd);
        }
Exemple #2
0
        internal WrappedCommand getTargetCmd(Interp interp)
        {
            TclObject[] objv = TclList.getElements(interp, prefix);

            string targetName = objv[0].ToString();

            return(NamespaceCmd.findCommand(targetInterp, targetName, null, 0));
        }
Exemple #3
0
        internal static void create(Interp interp, Interp slaveInterp, Interp masterInterp, TclObject name, TclObject targetName, int objIx, TclObject[] objv)
        {
            string inString = name.ToString();

            InterpAliasCmd alias = new InterpAliasCmd();

            alias.name = name;
            name.Preserve();

            alias.slaveInterp  = slaveInterp;
            alias.targetInterp = masterInterp;

            alias.prefix = TclList.NewInstance();
            alias.prefix.Preserve();
            TclList.Append(interp, alias.prefix, targetName);
            TclList.insert(interp, alias.prefix, 1, objv, objIx, objv.Length - 1);

            slaveInterp.CreateCommand(inString, alias);
            alias.slaveCmd = NamespaceCmd.findCommand(slaveInterp, inString, null, 0);

            try
            {
                interp.preventAliasLoop(slaveInterp, alias.slaveCmd);
            }
            catch (TclException e)
            {
                // Found an alias loop!  The last call to Tcl_CreateObjCommand made
                // the alias point to itself.  Delete the command and its alias
                // record.  Be careful to wipe out its client data first, so the
                // command doesn't try to delete itself.

                slaveInterp.DeleteCommandFromToken(alias.slaveCmd);
                throw;
            }

            // Make an entry in the alias table. If it already exists delete
            // the alias command. Then retry.

            if (slaveInterp._aliasTable.ContainsKey(inString))
            {
                InterpAliasCmd oldAlias = (InterpAliasCmd)slaveInterp._aliasTable[inString];
                slaveInterp.DeleteCommandFromToken(oldAlias.slaveCmd);
            }

            alias.aliasEntry = inString;
            SupportClass.PutElement(slaveInterp._aliasTable, inString, alias);

            // Create the new command. We must do it after deleting any old command,
            // because the alias may be pointing at a renamed alias, as in:
            //
            // interp alias {} foo {} bar		# Create an alias "foo"
            // rename foo zop				# Now rename the alias
            // interp alias {} foo {} zop		# Now recreate "foo"...

            SupportClass.PutElement(masterInterp._targetTable, alias.slaveCmd, slaveInterp);

            interp.SetResult(name);
        }
        internal static Interp create(Interp interp, TclObject path, bool safe)
        {
            Interp masterInterp;
            string pathString;

            TclObject[] objv = TclList.getElements(interp, path);

            if (objv.Length < 2)
            {
                masterInterp = interp;

                pathString = path.ToString();
            }
            else
            {
                TclObject obj = TclList.newInstance();

                TclList.insert(interp, obj, 0, objv, 0, objv.Length - 2);
                masterInterp = InterpCmd.getInterp(interp, obj);

                pathString = objv[objv.Length - 1].ToString();
            }
            if (!safe)
            {
                safe = masterInterp.isSafe;
            }

            if (masterInterp.slaveTable.ContainsKey(pathString))
            {
                throw new TclException(interp, "interpreter named \"" + pathString + "\" already exists, cannot create");
            }

            Interp         slaveInterp = new Interp();
            InterpSlaveCmd slave       = new InterpSlaveCmd();

            slaveInterp.slave = slave;
            slaveInterp.setAssocData("InterpSlaveCmd", slave);

            slave.masterInterp = masterInterp;
            slave.path         = pathString;
            slave.slaveInterp  = slaveInterp;

            masterInterp.createCommand(pathString, slaveInterp.slave);
            slaveInterp.slave.interpCmd = NamespaceCmd.findCommand(masterInterp, pathString, null, 0);

            SupportClass.PutElement(masterInterp.slaveTable, pathString, slaveInterp.slave);

            slaveInterp.setVar("tcl_interactive", "0", TCL.VarFlag.GLOBAL_ONLY);

            // Inherit the recursion limit.

            slaveInterp.maxNestingDepth = masterInterp.maxNestingDepth;

            if (safe)
            {
                try
                {
                    makeSafe(slaveInterp);
                }
                catch (TclException e)
                {
                    SupportClass.WriteStackTrace(e, Console.Error);
                }
            }
            else
            {
                //Tcl_Init(slaveInterp);
            }

            return(slaveInterp);
        }