コード例 #1
0
ファイル: InterpAliasCmd.cs プロジェクト: BclEx/GpuStructs
        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);
        }
コード例 #2
0
ファイル: LsetCmd.cs プロジェクト: BclEx/GpuStructs
        /// <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);
        }
コード例 #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);
        }