예제 #1
0
        /// <summary> Tcl_UpvarObjCmd -> UpvarCmd.cmdProc
        ///
        /// This procedure is invoked to process the "upvar" Tcl command.
        /// See the user documentation for details on what it does.
        /// </summary>

        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] objv)
        {
            CallFrame frame;
            string    frameSpec, otherVarName, myVarName;
            int       p;
            int       objc = objv.Length, objv_index;
            int       result;

            if (objv.Length < 3)
            {
                throw new TclNumArgsException(interp, 1, objv, "?level? otherVar localVar ?otherVar localVar ...?");
            }

            // Find the call frame containing each of the "other variables" to be
            // linked to.


            frameSpec = objv[1].ToString();
            // Java does not support passing a reference by refernece so use an array
            CallFrame[] frameArr = new CallFrame[1];
            result = CallFrame.GetFrame(interp, frameSpec, frameArr);
            frame  = frameArr[0];
            objc  -= (result + 1);
            if ((objc & 1) != 0)
            {
                throw new TclNumArgsException(interp, 1, objv, "?level? otherVar localVar ?otherVar localVar ...?");
            }
            objv_index = result + 1;


            // Iterate over each (other variable, local variable) pair.
            // Divide the other variable name into two parts, then call
            // MakeUpvar to do all the work of linking it to the local variable.

            for (; objc > 0; objc -= 2, objv_index += 2)
            {
                myVarName = objv[objv_index + 1].ToString();

                otherVarName = objv[objv_index].ToString();

                int otherLength = otherVarName.Length;
                p = otherVarName.IndexOf((System.Char) '(');
                if ((p != -1) && (otherVarName[otherLength - 1] == ')'))
                {
                    // This is an array variable name
                    Var.makeUpvar(interp, frame, otherVarName.Substring(0, (p) - (0)), otherVarName.Substring(p + 1, (otherLength - 1) - (p + 1)), 0, myVarName, 0);
                }
                else
                {
                    // This is a scalar variable name
                    Var.makeUpvar(interp, frame, otherVarName, null, 0, myVarName, 0);
                }
            }
            interp.ResetResult();
            return(TCL.CompletionCode.RETURN);
        }
예제 #2
0
        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] objv)
        {
            string    optLevel;
            int       result;
            CallFrame savedVarFrame, frame;
            int       objc = objv.Length;
            int       objv_index;
            TclObject cmd;

            if (objv.Length < 2)
            {
                throw new TclNumArgsException(interp, 1, objv, "?level? command ?arg ...?");
            }

            // Find the level to use for executing the command.


            optLevel = objv[1].ToString();
            // Java does not support passing a reference by refernece so use an array
            CallFrame[] frameArr = new CallFrame[1];
            result = CallFrame.GetFrame(interp, optLevel, frameArr);
            frame  = frameArr[0];

            objc -= (result + 1);
            if (objc == 0)
            {
                throw new TclNumArgsException(interp, 1, objv, "?level? command ?arg ...?");
            }
            objv_index = (result + 1);

            // Modify the interpreter state to execute in the given frame.

            savedVarFrame   = interp.VarFrame;
            interp.VarFrame = frame;

            // Execute the residual arguments as a command.

            if (objc == 1)
            {
                cmd = objv[objv_index];
            }
            else
            {
                cmd = TclString.NewInstance(Util.concat(objv_index, objv.Length - 1, objv));
            }
            cmd.Preserve();

            try
            {
                interp.Eval(cmd, 0);
            }
            catch (TclException e)
            {
                if (e.GetCompletionCode() == TCL.CompletionCode.ERROR)
                {
                    interp.AddErrorInfo("\n    (\"uplevel\" body line " + interp._errorLine + ")");
                }
                throw;
            }
            finally
            {
                interp.VarFrame = savedVarFrame;
                cmd.Release();
            }
            return(TCL.CompletionCode.RETURN);
        }