예제 #1
0
        /*
         *----------------------------------------------------------------------
         *
         * InfoArgsCmd --
         *
         *      Called to implement the "info args" command that returns the
         *      argument list for a procedure. Handles the following syntax:
         *
         *          info args procName
         *
         * Results:
         *      Returns if successful, raises TclException otherwise.
         *
         * Side effects:
         *      Returns a result in the interpreter's result object.
         *
         *----------------------------------------------------------------------
         */

        private static void InfoArgsCmd(Interp interp, TclObject[] objv)
        {
            string    name;
            Procedure proc;
            TclObject listObj;

            if (objv.Length != 3)
            {
                throw new TclNumArgsException(interp, 2, objv, "procname");
            }

            name = objv[2].ToString();
            proc = Procedure.findProc(interp, name);
            if (proc == null)
            {
                throw new TclException(interp, "\"" + name + "\" isn't a procedure");
            }

            // Build a return list containing the arguments.

            listObj = TclList.newInstance();
            for (int i = 0; i < proc.argList.Length; i++)
            {
                TclObject s = TclString.newInstance(proc.argList[i][0]);
                TclList.append(interp, listObj, s);
            }
            interp.setResult(listObj);
            return;
        }
예제 #2
0
        /*
         *----------------------------------------------------------------------
         *
         * InfoDefaultCmd --
         *
         *      Called to implement the "info default" command that returns the
         *      default value for a procedure argument. Handles the following
         *      syntax:
         *
         *          info default procName arg varName
         *
         * Results:
         *      Returns if successful, raises TclException otherwise.
         *
         * Side effects:
         *      Returns a result in the interpreter's result object.
         *
         *----------------------------------------------------------------------
         */

        private static void InfoDefaultCmd(Interp interp, TclObject[] objv)
        {
            string    procName, argName, varName;
            Procedure proc;

            //TclObject valueObj;

            if (objv.Length != 5)
            {
                throw new TclNumArgsException(interp, 2, objv, "procname arg varname");
            }


            procName = objv[2].ToString();

            argName = objv[3].ToString();
            proc    = Procedure.findProc(interp, procName);
            if (proc == null)
            {
                throw new TclException(interp, "\"" + procName + "\" isn't a procedure");
            }

            for (int i = 0; i < proc.argList.Length; i++)
            {
                if (argName.Equals(proc.argList[i][0].ToString()))
                {
                    varName = objv[4].ToString();
                    try
                    {
                        if (proc.argList[i][1] != null)
                        {
                            interp.setVar(varName, proc.argList[i][1], 0);
                            interp.setResult(1);
                        }
                        else
                        {
                            interp.setVar(varName, "", 0);
                            interp.setResult(0);
                        }
                    }
                    catch (TclException excp)
                    {
                        throw new TclException(interp, "couldn't store default value in variable \"" + varName + "\"");
                    }
                    return;
                }
            }
            throw new TclException(interp, "procedure \"" + procName + "\" doesn't have an argument \"" + argName + "\"");
        }
예제 #3
0
        /*
         *----------------------------------------------------------------------
         *
         * InfoBodyCmd --
         *
         *      Called to implement the "info body" command that returns the body
         *      for a procedure. Handles the following syntax:
         *
         *          info body procName
         *
         * Results:
         *      Returns if successful, raises TclException otherwise.
         *
         * Side effects:
         *      Returns a result in the interpreter's result object.
         *
         *----------------------------------------------------------------------
         */

        private static void InfoBodyCmd(Interp interp, TclObject[] objv)
        {
            string    name;
            Procedure proc;

            //TclObject body, result;

            if (objv.Length != 3)
            {
                throw new TclNumArgsException(interp, 2, objv, "procname");
            }

            name = objv[2].ToString();
            proc = Procedure.findProc(interp, name);
            if (proc == null)
            {
                throw new TclException(interp, "\"" + name + "\" isn't a procedure");
            }


            interp.setResult(proc.body.ToString());
            return;
        }