Ejemplo n.º 1
0
        public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
        {
            targetInterp.preserve();
            targetInterp.nestLevel++;

            targetInterp.resetResult();
            targetInterp.allowExceptions();

            // Append the arguments to the command prefix and invoke the command
            // in the target interp's global namespace.

            TclObject[] prefv = TclList.getElements(interp, prefix);
            TclObject   cmd   = TclList.newInstance();

            cmd.preserve();
            TclList.replace(interp, cmd, 0, 0, prefv, 0, prefv.Length - 1);
            TclList.replace(interp, cmd, prefv.Length, 0, argv, 1, argv.Length - 1);
            TclObject[] cmdv = TclList.getElements(interp, cmd);

            TCL.CompletionCode result = targetInterp.invoke(cmdv, Interp.INVOKE_NO_TRACEBACK);

            cmd.release();
            targetInterp.nestLevel--;

            // Check if we are at the bottom of the stack for the target interpreter.
            // If so, check for special return codes.

            if (targetInterp.nestLevel == 0)
            {
                if (result == TCL.CompletionCode.RETURN)
                {
                    result = targetInterp.updateReturnInfo();
                }
                if (result != TCL.CompletionCode.OK && result != TCL.CompletionCode.ERROR)
                {
                    try
                    {
                        targetInterp.processUnexpectedResult(result);
                    }
                    catch (TclException e)
                    {
                        result = e.getCompletionCode();
                    }
                }
            }

            targetInterp.release();
            interp.transferResult(targetInterp, result);
            return(TCL.CompletionCode.RETURN);
        }
Ejemplo n.º 2
0
        /// <summary> See Tcl user documentation for details.</summary>
        /// <exception cref=""> TclException If incorrect number of arguments.
        /// </exception>

        public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
        {
            if (argv.Length != 4)
            {
                throw new TclNumArgsException(interp, 1, argv, "lset list index element");
            }

            int       size        = TclList.getLength(interp, argv[1]);
            int       index       = Util.getIntForIndex(interp, argv[2], size);
            TclObject list        = argv[1];
            bool      isDuplicate = false;

            // If the list object is unshared we can modify it directly. Otherwise
            // we create a copy to modify: this is "copy on write".

            if (list.Shared)
            {
                list        = list.duplicate();
                isDuplicate = true;
            }

            try
            { TclObject[] replace = new TclObject[1];
              replace[0] = argv[3];
              TclList.replace(interp, list, index, 1, replace, 0, 0);
              interp.setResult(list); }
            catch (TclException e)
            {
                if (isDuplicate)
                {
                    list.release();
                }
                throw;
            }
            return(TCL.CompletionCode.RETURN);
        }
Ejemplo n.º 3
0
        /// <summary> See Tcl user documentation for details.</summary>
        /// <exception cref=""> TclException If incorrect number of arguments.
        /// </exception>

        public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
        {
            if (argv.Length < 4)
            {
                throw new TclNumArgsException(interp, 1, argv, "list first last ?element element ...?");
            }
            int size  = TclList.getLength(interp, argv[1]);
            int first = Util.getIntForIndex(interp, argv[2], size - 1);
            int last  = Util.getIntForIndex(interp, argv[3], size - 1);
            int numToDelete;

            if (first < 0)
            {
                first = 0;
            }

            // Complain if the user asked for a start element that is greater
            // than the list length. This won't ever trigger for the "end*"
            // case as that will be properly constrained by getIntForIndex
            // because we use size-1 (to allow for replacing the last elem).

            if ((first >= size) && (size > 0))
            {
                throw new TclException(interp, "list doesn't contain element " + argv[2]);
            }
            if (last >= size)
            {
                last = size - 1;
            }
            if (first <= last)
            {
                numToDelete = (last - first + 1);
            }
            else
            {
                numToDelete = 0;
            }

            TclObject list        = argv[1];
            bool      isDuplicate = false;

            // If the list object is unshared we can modify it directly. Otherwise
            // we create a copy to modify: this is "copy on write".

            if (list.Shared)
            {
                list        = list.duplicate();
                isDuplicate = true;
            }

            try
            {
                TclList.replace(interp, list, first, numToDelete, argv, 4, argv.Length - 1);
                interp.setResult(list);
            }
            catch (TclException e)
            {
                if (isDuplicate)
                {
                    list.release();
                }
                throw;
            }
            return(TCL.CompletionCode.RETURN);
        }