当前位置: 首页>>代码示例>>C#>>正文


C# Interp.setVar方法代码示例

本文整理汇总了C#中tcl.lang.Interp.setVar方法的典型用法代码示例。如果您正苦于以下问题:C# Interp.setVar方法的具体用法?C# Interp.setVar怎么用?C# Interp.setVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tcl.lang.Interp的用法示例。


在下文中一共展示了Interp.setVar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: initialize

    /*
    *----------------------------------------------------------------------
    *
    * initialize --
    *
    *	This method is called to initialize an interpreter with it's 
    *	initial values for the env array.
    *
    * Results:
    *	None.
    *
    * Side effects:
    *	The env array in the interpreter is created and populated.
    *
    *----------------------------------------------------------------------
    */

    internal static void initialize( Interp interp )
    {
      // For a few standrad environment vairables that Tcl users 
      // often assume aways exist (even if they shouldn't), we will
      // try to create those expected variables with the common unix
      // names.

      try
      {
        interp.setVar( "env", "HOME", System.Environment.CurrentDirectory, TCL.VarFlag.GLOBAL_ONLY );
      }
      catch ( TclException e )
      {
        // Ignore errors.
      }

      try
      {
        interp.setVar( "env", "USER", System.Environment.UserName, TCL.VarFlag.GLOBAL_ONLY );
      }
      catch ( TclException e )
      {
        // Ignore errors.
      }

      // Now we will populate the rest of the env array with the
      // properties recieved from the System classes.  This makes for 
      // a nice shortcut for getting to these useful values.

      try
      {


        for ( IDictionaryEnumerator search = System.Environment.GetEnvironmentVariables().GetEnumerator(); search.MoveNext(); )
        {
          interp.setVar( "env", search.Key.ToString(), search.Value.ToString(), TCL.VarFlag.GLOBAL_ONLY );
        }
      }
      catch ( System.Security.SecurityException e2 )
      {
        // We are inside a browser and we can't access the list of
        // property names. That's fine. Life goes on ....
      }
      catch ( System.Exception e3 )
      {
        // We are inside a browser and we can't access the list of
        // property names. That's fine. Life goes on ....

        System.Diagnostics.Debug.WriteLine( "Exception while initializing env array" );
        System.Diagnostics.Debug.WriteLine( e3 );
        System.Diagnostics.Debug.WriteLine( "" );
      }
    }
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:70,代码来源:Env.cs

示例2: cmdProc

    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] objv )
    {
      TclObject varValue = null;

      if ( objv.Length < 2 )
      {
        throw new TclNumArgsException( interp, 1, objv, "varName ?value value ...?" );
      }
      else if ( objv.Length == 2 )
      {
        interp.resetResult();
        interp.setResult( interp.getVar( objv[1], 0 ) );
      }
      else
      {
        for ( int i = 2; i < objv.Length; i++ )
        {
          varValue = interp.setVar( objv[1], objv[i], TCL.VarFlag.APPEND_VALUE );
        }

        if ( varValue != null )
        {
          interp.resetResult();
          interp.setResult( varValue );
        }
        else
        {
          interp.resetResult();
        }
      }
      return TCL.CompletionCode.RETURN;
    }
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:32,代码来源:AppendCmd.cs

示例3: cmdProc

    /// <summary> This procedure is invoked to process the "gets" Tcl command.
    /// See the user documentation for details on what it does.
    /// 
    /// </summary>
    /// <param name="interp">the current interpreter.
    /// </param>
    /// <param name="argv">command arguments.
    /// </param>

    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {

      bool writeToVar = false; // If true write to var passes as arg
      string varName = ""; // The variable to write value to
      Channel chan; // The channel being operated on
      int lineLen;
      TclObject line;

      if ( ( argv.Length < 2 ) || ( argv.Length > 3 ) )
      {
        throw new TclNumArgsException( interp, 1, argv, "channelId ?varName?" );
      }

      if ( argv.Length == 3 )
      {
        writeToVar = true;

        varName = argv[2].ToString();
      }


      chan = TclIO.getChannel( interp, argv[1].ToString() );
      if ( chan == null )
      {

        throw new TclException( interp, "can not find channel named \"" + argv[1].ToString() + "\"" );
      }

      try
      {
        line = TclString.newInstance( new StringBuilder( 64 ) );
        lineLen = chan.read( interp, line, TclIO.READ_LINE, 0 );
        if ( lineLen < 0 )
        {
          // FIXME: Need more specific posix error codes!
          if ( !chan.eof() && !chan.isBlocked( interp ) )
          {

            throw new TclPosixException( interp, TclPosixException.EIO, true, "error reading \"" + argv[1].ToString() + "\"" );
          }
          lineLen = -1;
        }
        if ( writeToVar )
        {
          interp.setVar( varName, line, 0 );
          interp.setResult( lineLen );
        }
        else
        {
          interp.setResult( line );
        }
      }
      catch ( IOException e )
      {
        throw new TclRuntimeError( "GetsCmd.cmdProc() Error: IOException when getting " + chan.ChanName + ": " + e.Message );
      }
      return TCL.CompletionCode.RETURN;
    }
开发者ID:R4P3-NET,项目名称:AccountingServerEmulatorSource,代码行数:68,代码来源:GetsCmd.cs

示例4: cmdProc

    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {
      bool debug;

      if ( argv.Length == 2 )
      {
        System.Diagnostics.Debug.WriteLine( "getting value of \"" + argv[1].ToString() + "\"" );

        interp.setResult( interp.getVar( argv[1], 0 ) );
      }
      else if ( argv.Length == 3 )
      {
        System.Diagnostics.Debug.WriteLine( "setting value of \"" + argv[1].ToString() + "\" to \"" + argv[2].ToString() + "\"" );
        interp.setResult( interp.setVar( argv[1], argv[2], 0 ) );
      }
      else
      {
        throw new TclNumArgsException( interp, 1, argv, "varName ?newValue?" );
      }
      return TCL.CompletionCode.RETURN;
    }
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:21,代码来源:SetCmd.cs

示例5: cmdProc

		/// <summary> This procedure is invoked to process the "catch" Tcl command.
		/// See the user documentation for details on what it does.
		/// 
		/// </summary>
		/// <param name="interp">the current interpreter.
		/// </param>
		/// <param name="argv">command arguments.
		/// </param>
		/// <exception cref=""> TclException if wrong number of arguments.
		/// </exception>
		
		public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
		{
			if (argv.Length != 2 && argv.Length != 3)
			{
				throw new TclNumArgsException(interp, 1, argv, "command ?varName?");
			}
			
			TclObject result;
			TCL.CompletionCode code = TCL.CompletionCode.OK;
			
			try
			{
				interp.eval(argv[1], 0);
			}
			catch (TclException e)
			{
				code = e.getCompletionCode();
			}

      result = interp.getResult();

      if ( argv.Length == 3 )
			{
				try
				{
					interp.setVar(argv[2], result, 0);
				}
				catch (TclException e)
				{
					throw new TclException(interp, "couldn't save command result in variable");
				}
			}
			
			interp.resetResult();
			interp.setResult(TclInteger.newInstance((int)code));
      return TCL.CompletionCode.RETURN;
    }
开发者ID:Belxjander,项目名称:Asuna,代码行数:48,代码来源:CatchCmd.cs

示例6: cmdProc

    public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
    {
      bool all = false;
      bool nocase = false;

      try
      {
        int i = 1;

        while ( argv[i].ToString().StartsWith( "-" ) )
        {
          int index = TclIndex.get( interp, argv[i], validOpts, "switch", 0 );
          i++;
          switch ( index )
          {

            case OPT_ALL:
              {
                all = true;
                break;
              }

            case OPT_NOCASE:
              {
                nocase = true;
                break;
              }

            case OPT_LAST:
              {
                goto opts_brk;
              }
          }
        }

opts_brk:
        ;


        TclObject exp = argv[i++];

        string inString = argv[i++].ToString();

        string subSpec = argv[i++].ToString();

        string varName = null;
        if (i != argv.Length) varName = argv[i++].ToString();
        if ( i != argv.Length )
        {
          throw new System.IndexOutOfRangeException();
        }

        Regexp r = TclRegexp.compile( interp, exp, nocase );

        int count = 0;
        string result;

        if ( all == false )
        {
          result = r.sub( inString, subSpec );
          if ( (System.Object)result == null )
          {
            result = inString;
          }
          else
          {
            count++;
          }
        }
        else
        {
          StringBuilder sb = new StringBuilder();
          Regsub s = new Regsub( r, inString );
          while ( s.nextMatch() )
          {
            count++;
            sb.Append( s.skipped() );
            Regexp.applySubspec( s, subSpec, sb );
          }
          sb.Append( s.rest() );
          result = sb.ToString();
        }

        TclObject obj = TclString.newInstance( result );
        if ( varName == null )
          interp.setResult( result );
        else {
          try
          {
            interp.setVar( varName, obj, 0 );
          }
          catch ( TclException e )
          {
            throw new TclException( interp, "couldn't set variable \"" + varName + "\"" );
          }
          interp.setResult( count );
        }
      }
      catch ( System.IndexOutOfRangeException e )
      {
//.........这里部分代码省略.........
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:101,代码来源:RegsubCmd.cs

示例7: create

    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;
    }
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:71,代码来源:InterpSlaveCmd.cs

示例8: cmdProc

		public TCL.CompletionCode cmdProc(Interp interp, TclObject[] argv)
		{
			bool nocase = false;
			bool indices = false;
			
			try
			{
				int i = 1;
				
				while (argv[i].ToString().StartsWith("-"))
				{
					int index = TclIndex.get(interp, argv[i], validOpts, "switch", 0);
					i++;
					switch (index)
					{
						
						case OPT_INDICES:  {
								indices = true;
								break;
							}
						
						case OPT_NOCASE:  {
								nocase = true;
								break;
							}
						
						case OPT_LAST:  {
								goto opts_brk;
							}
						}
				}

opts_brk: ;


        TclObject exp = TclString.newInstance( argv[i++].ToString().Replace( "\\d", "[0-9]" ) );
				
				string inString = argv[i++].ToString();
				
				int matches = argv.Length - i;
				
				Regexp r = TclRegexp.compile(interp, exp, nocase);
				
				int[] args = new int[matches * 2];
				bool matched = r.match(inString, args);
				if (matched)
				{
					for (int match = 0; i < argv.Length; i++)
					{
						TclObject obj;
						
						int start = args[match++];
						int end = args[match++];
						if (indices)
						{
							if (end >= 0)
							{
								end--;
							}
							obj = TclList.newInstance();
							TclList.append(interp, obj, TclInteger.newInstance(start));
							TclList.append(interp, obj, TclInteger.newInstance(end));
						}
						else
						{
							string range = (start >= 0)?inString.Substring(start, (end) - (start)):"";
							obj = TclString.newInstance(range);
						}
						try
						{
							
							interp.setVar(argv[i].ToString(), obj, 0);
						}
						catch (TclException e)
						{
							
							throw new TclException(interp, "couldn't set variable \"" + argv[i] + "\"");
						}
					}
				}
				interp.setResult(matched);
			}
			catch (System.IndexOutOfRangeException e)
			{
				throw new TclNumArgsException(interp, 1, argv, "?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?");
			}
      return TCL.CompletionCode.RETURN;
    }
开发者ID:Belxjander,项目名称:Asuna,代码行数:88,代码来源:RegexpCmd.cs

示例9: getAndStoreStatData

    private static void getAndStoreStatData( Interp interp, string fileName, string varName )
    {
      FileInfo fileObj = FileUtil.getNewFileObj( interp, fileName );

      bool tmpBool;
      if ( File.Exists( fileObj.FullName ) )
        tmpBool = true;
      else
        tmpBool = Directory.Exists( fileObj.FullName );
      if ( !tmpBool )
      {
        throw new TclPosixException( interp, TclPosixException.ENOENT, true, "could not read \"" + fileName + "\"" );
      }

      try
      {
        int mtime = getMtime( interp, fileName, fileObj );
        TclObject mtimeObj = TclInteger.newInstance( mtime );
        TclObject atimeObj = TclInteger.newInstance( mtime );
        TclObject ctimeObj = TclInteger.newInstance( mtime );
        interp.setVar( varName, "atime", atimeObj, 0 );
        interp.setVar( varName, "ctime", ctimeObj, 0 );
        interp.setVar( varName, "mtime", mtimeObj, 0 );
      }
      catch ( System.Security.SecurityException e )
      {
        throw new TclException( interp, e.Message );
      }
      catch ( TclException e )
      {
        throw new TclException( interp, "can't set \"" + varName + "(dev)\": variable isn't array" );
      }

      try
      {
        TclObject sizeObj = TclInteger.newInstance( (int)SupportClass.FileLength( fileObj ) );
        interp.setVar( varName, "size", sizeObj, 0 );
      }
      catch ( System.Exception e )
      {
        // Do nothing.
      }

      try
      {
        TclObject typeObj = TclString.newInstance( getType( interp, fileName, fileObj ) );
        interp.setVar( varName, "type", typeObj, 0 );
      }
      catch ( System.Exception e )
      {
      }

      try
      {
        TclObject uidObj = TclBoolean.newInstance( isOwner( interp, fileObj ) );
        interp.setVar( varName, "uid", uidObj, 0 );
      }
      catch ( TclException e )
      {
        // Do nothing.
      }
    }
开发者ID:R4P3-NET,项目名称:AccountingServerEmulatorSource,代码行数:62,代码来源:FileCmd.cs

示例10: cmdProc

		/// <summary> 
		/// Tcl_LappendObjCmd -> LappendCmd.cmdProc
		/// 
		/// This procedure is invoked to process the "lappend" Tcl command.
		/// See the user documentation for details on what it does.
		/// </summary>
		
		public TCL.CompletionCode cmdProc(Interp interp, TclObject[] objv)
		{
			TclObject varValue, newValue = null;
      int i;//int numElems, i, j;
			bool createdNewObj, createVar;
			
			if (objv.Length < 2)
			{
				throw new TclNumArgsException(interp, 1, objv, "varName ?value value ...?");
			}
			if (objv.Length == 2)
			{
				try
				{
					newValue = interp.getVar(objv[1], 0);
				}
				catch (TclException e)
				{
					// The variable doesn't exist yet. Just create it with an empty
					// initial value.
					varValue = TclList.newInstance();
					
					try
					{
						newValue = interp.setVar(objv[1], varValue, 0);
					}
					finally
					{
						if (newValue == null)
							varValue.release(); // free unneeded object
					}
					
					interp.resetResult();
          return TCL.CompletionCode.RETURN;
				}
			}
			else
			{
				// We have arguments to append. We used to call Tcl_SetVar2 to
				// append each argument one at a time to ensure that traces were run
				// for each append step. We now append the arguments all at once
				// because it's faster. Note that a read trace and a write trace for
				// the variable will now each only be called once. Also, if the
				// variable's old value is unshared we modify it directly, otherwise
				// we create a new copy to modify: this is "copy on write".
				
				createdNewObj = false;
				createVar = true;
				
				try
				{
					varValue = interp.getVar(objv[1], 0);
				}
				catch (TclException e)
				{
					// We couldn't read the old value: either the var doesn't yet
					// exist or it's an array element. If it's new, we will try to
					// create it with Tcl_ObjSetVar2 below.
					
					// FIXME : not sure we even need this parse for anything!
					// If we do not need to parse could we at least speed it up a bit
					
					string varName;
					int nameBytes;
					
					
					varName = objv[1].ToString();
					nameBytes = varName.Length; // Number of Unicode chars in string
					
					for (i = 0; i < nameBytes; i++)
					{
						if (varName[i] == '(')
						{
							i = nameBytes - 1;
							if (varName[i] == ')')
							{
								// last char is ')' => array ref
								createVar = false;
							}
							break;
						}
					}
					varValue = TclList.newInstance();
					createdNewObj = true;
				}
				
				// We only take this branch when the catch branch was not run
				if (createdNewObj == false && varValue.Shared)
				{
					varValue = varValue.duplicate();
					createdNewObj = true;
				}
				
//.........这里部分代码省略.........
开发者ID:Belxjander,项目名称:Asuna,代码行数:101,代码来源:LappendCmd.cs

示例11: InfoDefaultCmd

    /*
    *----------------------------------------------------------------------
    *
    * 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 + "\"" );
    }
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:70,代码来源:InfoCmd.cs

示例12: cmdProc

		/// <summary> Tcl_ForeachObjCmd -> ForeachCmd.cmdProc
		/// 
		/// This procedure is invoked to process the "foreach" Tcl command.
		/// See the user documentation for details on what it does.
		/// 
		/// </summary>
		/// <param name="interp">the current interpreter.
		/// </param>
		/// <param name="objv">command arguments.
		/// </param>
		/// <exception cref=""> TclException if script causes error.
		/// </exception>
		
		public TCL.CompletionCode cmdProc(Interp interp, TclObject[] objv)
		{
			if (objv.Length < 4 || (objv.Length % 2) != 0)
			{
				throw new TclNumArgsException(interp, 1, objv, "varList list ?varList list ...? command");
			}
			
			// foreach {n1 n2} {1 2 3 4} {n3} {1 2} {puts $n1-$n2-$n3}
			//	name[0] = {n1 n2}	value[0] = {1 2 3 4}
			//	name[1] = {n3}		value[0] = {1 2}
			
			TclObject[] name = new TclObject[(objv.Length - 2) / 2];
			TclObject[] value = new TclObject[(objv.Length - 2) / 2];
			
			int c, i, j, base_;
			int maxIter = 0;
			TclObject command = objv[objv.Length - 1];
			bool done = false;
			
			for (i = 0; i < objv.Length - 2; i += 2)
			{
				int x = i / 2;
				name[x] = objv[i + 1];
				value[x] = objv[i + 2];
				
				int nSize = TclList.getLength(interp, name[x]);
				int vSize = TclList.getLength(interp, value[x]);
				
				if (nSize == 0)
				{
					throw new TclException(interp, "foreach varlist is empty");
				}
				
				int iter = (vSize + nSize - 1) / nSize;
				if (maxIter < iter)
				{
					maxIter = iter;
				}
			}
			
			for (c = 0; !done && c < maxIter; c++)
			{
				// Set up the variables
				
				for (i = 0; i < objv.Length - 2; i += 2)
				{
					int x = i / 2;
					int nSize = TclList.getLength(interp, name[x]);
					base_ = nSize * c;
					for (j = 0; j < nSize; j++)
					{
						// Test and see if the name variable is an array.
						
						
						Var[] result = Var.lookupVar(interp, name[x].ToString(), null, 0, null, false, false);
						Var var = null;
						
						if (result != null)
						{
							if (result[1] != null)
							{
								var = result[1];
							}
							else
							{
								var = result[0];
							}
						}
						
						try
						{
							if (base_ + j >= TclList.getLength(interp, value[x]))
							{
								interp.setVar(TclList.index(interp, name[x], j), TclString.newInstance(""), 0);
							}
							else
							{
								interp.setVar(TclList.index(interp, name[x], j), TclList.index(interp, value[x], base_ + j), 0);
							}
						}
						catch (TclException e)
						{
							
							throw new TclException(interp, "couldn't set loop variable: \"" + TclList.index(interp, name[x], j) + "\"");
						}
					}
				}
//.........这里部分代码省略.........
开发者ID:Belxjander,项目名称:Asuna,代码行数:101,代码来源:ForeachCmd.cs

示例13: cmdProc


//.........这里部分代码省略.........
              {
                interp.setResult( "" );
              }
            }
            break;
          }

        case OPT_SET:
          {

            if ( objv.Length != 4 )
            {
              throw new TclNumArgsException( interp, 2, objv, "arrayName list" );
            }
            int size = TclList.getLength( interp, objv[3] );
            if ( size % 2 != 0 )
            {
              throw new TclException( interp, "list must have an even number of elements" );
            }

            int i;

            string name1 = objv[2].ToString();
            string name2, strValue;

            // Set each of the array variable names in the interp

            for ( i = 0; i < size; i++ )
            {

              name2 = TclList.index( interp, objv[3], i++ ).ToString();

              strValue = TclList.index( interp, objv[3], i ).ToString();
              interp.setVar( name1, name2, TclString.newInstance( strValue ), 0 );
            }
            break;
          }

        case OPT_SIZE:
          {

            if ( objv.Length != 3 )
            {
              throw new TclNumArgsException( interp, 2, objv, "arrayName" );
            }
            if ( notArray )
            {
              interp.setResult( 0 );
            }
            else
            {
              Hashtable table = (Hashtable)var.value;
              int size = 0;
              for ( IDictionaryEnumerator e = table.GetEnumerator(); e.MoveNext(); )
              {
                Var elem = (Var)e.Value;
                if ( ( elem.flags & VarFlags.UNDEFINED ) == 0 )
                {
                  size++;
                }
              }
              interp.setResult( size );
            }
            break;
          }
开发者ID:R4P3-NET,项目名称:AccountingServerEmulatorSource,代码行数:66,代码来源:ArrayCmd.cs

示例14: testAndSetVar

    /// <summary> Called whenever the cmdProc wants to set an interp value.  
    /// This method <ol>
    /// <li> verifies that there exisits a varName from the argv array, 
    /// <li> that the variable either dosent exisit or is of type scalar
    /// <li> set the variable in interp if (1) and (2) are OK
    /// </ol>
    /// 
    /// </summary>
    /// <param name="interp">  - the Tcl interpreter
    /// </param>
    /// <param name="argv">    - the argument array
    /// </param>
    /// <param name="argIndex">- the current index into the argv array
    /// </param>
    /// <param name="tobj">    - the TclObject that the varName equals
    /// 
    /// </param>

    private static void testAndSetVar( Interp interp, TclObject[] argv, int argIndex, TclObject tobj )
    {
      if ( argIndex < argv.Length )
      {
        try
        {

          interp.setVar( argv[argIndex].ToString(), tobj, 0 );
        }
        catch ( TclException e )
        {

          throw new TclException( interp, "couldn't set variable \"" + argv[argIndex].ToString() + "\"" );
        }
      }
      else
      {
        errorDiffVars( interp );
      }
    }
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:38,代码来源:ScanCmd.cs

示例15: Main

  /*
  ** 2009 July 17
  **
  ** The author disclaims copyright to this source code.  In place of
  ** a legal notice, here is a blessing:
  **
  **    May you do good and not evil.
  **    May you find forgiveness for yourself and forgive others.
  **    May you share freely, never taking more than you give.
  **
  *************************************************************************
  ** This file contains code to implement the "sqlite" test harness
  ** which runs TCL commands for testing the C#-SQLite port.
  **
  ** $Header$
  */
  public static void Main(string[] args)
  {
    // Array of command-line argument strings.
    {
      string fileName = null;

      // Create the interpreter. This will also create the built-in
      // Tcl commands.

      Interp interp = new Interp();

      // Make command-line arguments available in the Tcl variables "argc"
      // and "argv".  If the first argument doesn't start with a "-" then
      // strip it off and use it as the name of a script file to process.
      // We also set the argv0 and TCL.Tcl_interactive vars here.

      if ((args.Length > 0) && !(args[0].StartsWith("-")))
      {
        fileName = args[0];
      }

      TclObject argv = TclList.newInstance();
      argv.preserve();
      try
      {
        int i = 0;
        int argc = args.Length;
        if ((System.Object)fileName == null)
        {
          interp.setVar("argv0", "tcl.lang.Shell", TCL.VarFlag.GLOBAL_ONLY);
          interp.setVar("tcl_interactive", "1", TCL.VarFlag.GLOBAL_ONLY);
        }
        else
        {
          interp.setVar("argv0", fileName, TCL.VarFlag.GLOBAL_ONLY);
          interp.setVar("tcl_interactive", "0", TCL.VarFlag.GLOBAL_ONLY);
          i++;
          argc--;
        }
        for (; i < args.Length; i++)
        {
          TclList.append(interp, argv, TclString.newInstance(args[i]));
        }
        interp.setVar("argv", argv, TCL.VarFlag.GLOBAL_ONLY);
        interp.setVar("argc", System.Convert.ToString(argc), TCL.VarFlag.GLOBAL_ONLY);
      }
      catch (TclException e)
      {
        throw new TclRuntimeError("unexpected TclException: " + e.Message);
      }
      finally
      {
        argv.release();
      }

      // Normally we would do application specific initialization here.
      // However, that feature is not currently supported.
      // If a script file was specified then just source that file
      // and quit.

      Console.WriteLine("C#-TCL version " + Assembly.GetExecutingAssembly().GetName().Version.ToString());
      Console.WriteLine("==============================================================");
      Console.WriteLine("");

      if ((System.Object)fileName != null)
      {
        try
        {
          interp.evalFile(fileName);
        }
        catch (TclException e)
        {
          TCL.CompletionCode code = e.getCompletionCode();
          if (code == TCL.CompletionCode.RETURN)
          {
            code = interp.updateReturnInfo();
            if (code != TCL.CompletionCode.OK)
            {
              System.Console.Error.WriteLine("command returned bad code: " + code);
              if (tcl.lang.ConsoleThread.debug) System.Diagnostics.Debug.WriteLine("command returned bad code: " + code);
            }
          }
          else if (code == TCL.CompletionCode.ERROR)
          {
//.........这里部分代码省略.........
开发者ID:Jaden-J,项目名称:csharp-sqlite,代码行数:101,代码来源:csTCL.cs


注:本文中的tcl.lang.Interp.setVar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。