示例#1
0
文件: Util.cs 项目: Belxjander/Asuna
    public void traceProc( Interp interp, string name1, string name2, TCL.VarFlag flags )
    {
      // If the variable is unset, then recreate the trace and restore
      // the default value of the format string.

      if ( ( flags & TCL.VarFlag.TRACE_UNSETS ) != 0 )
      {
        if ( ( ( flags & TCL.VarFlag.TRACE_DESTROYED ) != 0 ) && ( ( flags & TCL.VarFlag.INTERP_DESTROYED ) == 0 ) )
        {
          interp.traceVar( name1, name2, new PrecTraceProc(), TCL.VarFlag.GLOBAL_ONLY | TCL.VarFlag.TRACE_WRITES | TCL.VarFlag.TRACE_READS | TCL.VarFlag.TRACE_UNSETS );
          Util.precision = Util.DEFAULT_PRECISION;
        }
        return;
      }

      // When the variable is read, reset its value from our shared
      // value. This is needed in case the variable was modified in
      // some other interpreter so that this interpreter's value is
      // out of date.

      if ( ( flags & TCL.VarFlag.TRACE_READS ) != 0 )
      {
        interp.setVar( name1, name2, TclInteger.newInstance( Util.precision ), flags & TCL.VarFlag.GLOBAL_ONLY );
        return;
      }

      // The variable is being written. Check the new value and disallow
      // it if it isn't reasonable.
      //
      // (ToDo) Disallow it if this is a safe interpreter (we don't want
      // safe interpreters messing up the precision of other
      // interpreters).

      TclObject tobj = null;
      try
      {
        tobj = interp.getVar( name1, name2, ( flags & TCL.VarFlag.GLOBAL_ONLY ) );
      }
      catch ( TclException e )
      {
        // Do nothing when var does not exist.
      }

      string value;

      if ( tobj != null )
      {

        value = tobj.ToString();
      }
      else
      {
        value = "";
      }

      StrtoulResult r = Util.strtoul( value, 0, 10 );

      if ( ( r == null ) || ( r.value <= 0 ) || ( r.value > TCL_MAX_PREC ) || ( r.value > 100 ) || ( r.index == 0 ) || ( r.index != value.Length ) )
      {
        interp.setVar( name1, name2, TclInteger.newInstance( Util.precision ), TCL.VarFlag.GLOBAL_ONLY );
        throw new TclException( interp, "improper value for precision" );
      }

      Util.precision = (int)r.value;
    }
示例#2
0
文件: Util.cs 项目: Belxjander/Asuna
 internal static void setupPrecisionTrace( Interp interp )
 // Current interpreter.
 {
   try
   {
     interp.traceVar( "tcl_precision", new PrecTraceProc(), TCL.VarFlag.GLOBAL_ONLY | TCL.VarFlag.TRACE_WRITES | TCL.VarFlag.TRACE_READS | TCL.VarFlag.TRACE_UNSETS );
   }
   catch ( TclException e )
   {
     throw new TclRuntimeError( "unexpected TclException: " + e.Message, e );
   }
 }