Exemplo n.º 1
0
    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;
    }