本文整理汇总了C#中tcl.lang.TCL类的典型用法代码示例。如果您正苦于以下问题:C# TCL类的具体用法?C# TCL怎么用?C# TCL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TCL类属于tcl.lang命名空间,在下文中一共展示了TCL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TclException
public TclException(TCL.CompletionCode ccode):base()
{
if (ccode == TCL.CompletionCode.OK)
{
throw new TclRuntimeError("The reserved completion code TCL.CompletionCode.OK (0) cannot be used");
}
compCode = ccode;
errIndex = - 1;
}
示例2: traceVar
public void traceVar( string part1, string part2, VarTrace trace, TCL.VarFlag flags )
{
Var.traceVar( this, part1, part2, flags, trace );
}
示例3: getVar
/// <summary> TCL.Tcl_GetVar2Ex -> getVar
///
/// Query the value of a variable, given a two-part name consisting
/// of array name and element within array.
///
/// </summary>
/// <param name="interp">the interp that holds the variable
/// </param>
/// <param name="part1">1st part of the variable name.
/// </param>
/// <param name="part2">2nd part of the variable name.
/// </param>
/// <param name="flags">misc flags that control the actions of this method.
/// </param>
/// <returns> the value of the variable.
/// </returns>
internal static TclObject getVar( Interp interp, string part1, string part2, TCL.VarFlag flags )
{
Var[] result = lookupVar( interp, part1, part2, flags, "read", false, true );
if ( result == null )
{
// lookupVar() returns null only if TCL.VarFlag.LEAVE_ERR_MSG is
// not part of the flags argument, return null in this case.
return null;
}
Var var = result[0];
Var array = result[1];
try
{
// Invoke any traces that have been set for the variable.
if ( ( var.traces != null ) || ( ( array != null ) && ( array.traces != null ) ) )
{
string msg = callTraces( interp, array, var, part1, part2, ( flags & ( TCL.VarFlag.NAMESPACE_ONLY | TCL.VarFlag.GLOBAL_ONLY ) ) | TCL.VarFlag.TRACE_READS );
if ( (System.Object)msg != null )
{
if ( ( flags & TCL.VarFlag.LEAVE_ERR_MSG ) != 0 )
{
throw new TclVarException( interp, part1, part2, "read", msg );
}
return null;
}
}
if ( var.isVarScalar() && !var.isVarUndefined() )
{
return (TclObject)var.value;
}
if ( var.isSQLITE3_Link() )
return var.sqlite3_get();
if ( ( flags & TCL.VarFlag.LEAVE_ERR_MSG ) != 0 )
{
string msg;
if ( var.isVarUndefined() && ( array != null ) && !array.isVarUndefined() )
{
msg = noSuchElement;
}
else if ( var.isVarArray() )
{
msg = isArray;
}
else
{
msg = noSuchVar;
}
throw new TclVarException( interp, part1, part2, "read", msg );
}
}
finally
{
// If the variable doesn't exist anymore and no-one's using it,
// then free up the relevant structures and hash table entries.
if ( var.isVarUndefined() )
{
cleanupVar( var, array );
}
}
return null;
}
示例4: lookupVar
/// <summary> TclLookupVar -> lookupVar
///
/// This procedure is used by virtually all of the variable
/// code to locate a variable given its name(s).
///
/// </summary>
/// <param name="part1">if part2 isn't NULL, this is the name of an array.
/// Otherwise, this is a full variable name that could include
/// a parenthesized array elemnt or a scalar.
/// </param>
/// <param name="part2">Name of an element within array, or null.
/// </param>
/// <param name="flags">Only the TCL.VarFlag.GLOBAL_ONLY bit matters.
/// </param>
/// <param name="msg">Verb to use in error messages, e.g. "read" or "set".
/// </param>
/// <param name="create">OR'ed combination of CRT_PART1 and CRT_PART2.
/// Tells which entries to create if they don't already exist.
/// </param>
/// <param name="throwException">true if an exception should be throw if the
/// variable cannot be found.
/// </param>
/// <returns> a two element array. a[0] is the variable indicated by
/// part1 and part2, or null if the variable couldn't be
/// found and throwException is false.
/// <p>
/// If the variable is found, a[1] is the array that
/// contains the variable (or null if the variable is a scalar).
/// If the variable can't be found and either createPart1 or
/// createPart2 are true, a new as-yet-undefined (VAR_UNDEFINED)
/// variable instance is created, entered into a hash
/// table, and returned.
/// Note: it's possible that var.value of the returned variable
/// may be null (variable undefined), even if createPart1 or createPart2
/// are true (these only cause the hash table entry or array to be created).
/// For example, the variable might be a global that has been unset but
/// is still referenced by a procedure, or a variable that has been unset
/// but it only being kept in existence by a trace.
/// </returns>
/// <exception cref=""> TclException if the variable cannot be found and
/// throwException is true.
///
/// </exception>
internal static Var[] lookupVar( Interp interp, string part1, string part2, TCL.VarFlag flags, string msg, bool createPart1, bool createPart2 )
{
CallFrame varFrame = interp.varFrame;
// Reference to the procedure call frame whose
// variables are currently in use. Same as
// the current procedure's frame, if any,
// unless an "uplevel" is executing.
Hashtable table; // to the hashtable, if any, in which
// to look up the variable.
Var var; // Used to search for global names.
string elName; // Name of array element or null.
int openParen;
// If this procedure parses a name into
// array and index, these point to the
// parens around the index. Otherwise they
// are -1. These are needed to restore
// the parens after parsing the name.
NamespaceCmd.Namespace varNs, cxtNs;
int p;
int i, result;
var = null;
openParen = -1;
varNs = null; // set non-null if a nonlocal variable
// Parse part1 into array name and index.
// Always check if part1 is an array element name and allow it only if
// part2 is not given.
// (if one does not care about creating array elements that can't be used
// from tcl, and prefer slightly better performance, one can put
// the following in an if (part2 == null) { ... } block and remove
// the part2's test and error reporting or move that code in array set)
elName = part2;
int len = part1.Length;
for ( p = 0; p < len; p++ )
{
if ( part1[p] == '(' )
{
openParen = p;
p = len - 1;
if ( part1[p] == ')' )
{
if ( (System.Object)part2 != null )
{
if ( ( flags & TCL.VarFlag.LEAVE_ERR_MSG ) != 0 )
{
throw new TclVarException( interp, part1, part2, msg, needArray );
}
return null;
}
elName = part1.Substring( openParen + 1, ( len - 1 ) - ( openParen + 1 ) );
part2 = elName; // same as elName, only used in error reporting
part1 = part1.Substring( 0, ( openParen ) - ( 0 ) );
}
break;
}
//.........这里部分代码省略.........
示例5: callTraces
/// <summary> CallTraces -> callTraces
///
/// This procedure is invoked to find and invoke relevant
/// trace procedures associated with a particular operation on
/// a variable. This procedure invokes traces both on the
/// variable and on its containing array (where relevant).
///
/// </summary>
/// <param name="interp">Interpreter containing variable.
/// </param>
/// <param name="array">array variable that contains the variable, or null
/// if the variable isn't an element of an array.
/// </param>
/// <param name="var">Variable whose traces are to be invoked.
/// </param>
/// <param name="part1">the first part of a variable name.
/// </param>
/// <param name="part2">the second part of a variable name.
/// </param>
/// <param name="flags">Flags to pass to trace procedures: indicates
/// what's happening to variable, plus other stuff like
/// TCL.VarFlag.GLOBAL_ONLY, TCL.VarFlag.NAMESPACE_ONLY, and TCL.VarFlag.INTERP_DESTROYED.
/// </param>
/// <returns> null if no trace procedures were invoked, or
/// if all the invoked trace procedures returned successfully.
/// The return value is non-null if a trace procedure returned an
/// error (in this case no more trace procedures were invoked
/// after the error was returned). In this case the return value
/// is a pointer to a string describing the error.
/// </returns>
static protected internal string callTraces( Interp interp, Var array, Var var, string part1, string part2, TCL.VarFlag flags )
{
TclObject oldResult;
int i;
// If there are already similar trace procedures active for the
// variable, don't call them again.
if ( ( var.flags & VarFlags.TRACE_ACTIVE ) != 0 )
{
return null;
}
var.flags |= VarFlags.TRACE_ACTIVE;
var.refCount++;
// If the variable name hasn't been parsed into array name and
// element, do it here. If there really is an array element,
// make a copy of the original name so that nulls can be
// inserted into it to separate the names (can't modify the name
// string in place, because the string might get used by the
// callbacks we invoke).
// FIXME : come up with parsing code to use for all situations!
if ( (System.Object)part2 == null )
{
int len = part1.Length;
if ( len > 0 )
{
if ( part1[len - 1] == ')' )
{
for ( i = 0; i < len - 1; i++ )
{
if ( part1[i] == '(' )
{
break;
}
}
if ( i < len - 1 )
{
if ( i < len - 2 )
{
part2 = part1.Substring( i + 1, ( len - 1 ) - ( i + 1 ) );
part1 = part1.Substring( 0, ( i ) - ( 0 ) );
}
}
}
}
}
oldResult = interp.getResult();
oldResult.preserve();
interp.resetResult();
try
{
// Invoke traces on the array containing the variable, if relevant.
if ( array != null )
{
array.refCount++;
}
if ( ( array != null ) && ( array.traces != null ) )
{
for ( i = 0; ( array.traces != null ) && ( i < array.traces.Count ); i++ )
{
TraceRecord rec = (TraceRecord)array.traces[i];
if ( ( rec.flags & flags ) != 0 )
{
//.........这里部分代码省略.........
示例6: getTraces
/// <summary> TCL.Tcl_VarTraceInfo2 -> getTraces
///
/// </summary>
/// <returns> the list of traces of a variable.
///
/// </returns>
/// <param name="interp">Interpreter containing variable.
/// </param>
/// <param name="part1">1st part of the variable name.
/// </param>
/// <param name="part2">2nd part of the variable name (can be null).
/// </param>
/// <param name="flags">misc flags that control the actions of this method.
/// </param>
static protected internal ArrayList getTraces( Interp interp, string part1, string part2, TCL.VarFlag flags )
{
Var[] result;
result = lookupVar( interp, part1, part2, flags & ( TCL.VarFlag.GLOBAL_ONLY | TCL.VarFlag.NAMESPACE_ONLY ), null, false, false );
if ( result == null )
{
return null;
}
return result[0].traces;
}
示例7: untraceVar
/// <summary> TCL.Tcl_UntraceVar2 -> untraceVar
///
/// Untrace a variable, given a two-part name consisting of array
/// name and element within array. This will Remove a
/// previously-created trace for a variable.
///
/// </summary>
/// <param name="interp">Interpreter containing variable.
/// </param>
/// <param name="part1">1st part of the variable name.
/// </param>
/// <param name="part2">2nd part of the variable name.
/// </param>
/// <param name="flags">misc flags that control the actions of this method.
/// </param>
/// <param name="proc">the trace to delete.
/// </param>
internal static void untraceVar( Interp interp, string part1, string part2, TCL.VarFlag flags, VarTrace proc )
{
Var[] result = null;
Var var;
try
{
result = lookupVar( interp, part1, part2, flags & ( TCL.VarFlag.GLOBAL_ONLY | TCL.VarFlag.NAMESPACE_ONLY ), null, false, false );
if ( result == null )
{
return;
}
}
catch ( TclException e )
{
// FIXME: check for problems in exception in lookupVar
// We have set throwException argument to false in the
// lookupVar() call, so an exception should never be
// thrown.
throw new TclRuntimeError( "unexpected TclException: " + e.Message, e );
}
var = result[0];
if ( var.traces != null )
{
int len = var.traces.Count;
for ( int i = 0; i < len; i++ )
{
TraceRecord rec = (TraceRecord)var.traces[i];
if ( rec.trace == proc )
{
var.traces.RemoveAt( i );
break;
}
}
}
// If this is the last trace on the variable, and the variable is
// unset and unused, then free up the variable.
if ( var.isVarUndefined() )
{
cleanupVar( var, null );
}
}
示例8: TclException
public TclException( Interp interp, string msg, TCL.CompletionCode ccode )
: this( interp, msg, ccode, -1 )
{
}
示例9: setCompletionCode
internal void setCompletionCode( TCL.CompletionCode ccode )
// New completion code.
{
if ( ccode == TCL.CompletionCode.OK )
{
throw new TclRuntimeError( "The reserved completion code TCL.CompletionCode.OK (0) cannot be used" );
}
compCode = ccode;
}
示例10: traceProc
public void traceProc(Interp interp, string part1, string part2, TCL.VarFlag flags)
{
if (((this.flags & flags) != 0) && ((flags & TCL.VarFlag.INTERP_DESTROYED) == 0))
{
System.Text.StringBuilder sbuf = new System.Text.StringBuilder(command);
try
{
Util.appendElement(interp, sbuf, part1);
if ((System.Object) part2 != null)
{
Util.appendElement(interp, sbuf, part2);
}
else
{
Util.appendElement(interp, sbuf, "");
}
if ((flags & TCL.VarFlag.TRACE_READS) != 0)
{
Util.appendElement(interp, sbuf, "r");
}
else if ((flags & TCL.VarFlag.TRACE_WRITES) != 0)
{
Util.appendElement(interp, sbuf, "w");
}
else if ((flags & TCL.VarFlag.TRACE_UNSETS) != 0)
{
Util.appendElement(interp, sbuf, "u");
}
}
catch (TclException e)
{
throw new TclRuntimeError("unexpected TclException: " + e.Message,e);
}
// Execute the command.
interp.eval(sbuf.ToString(), 0);
}
}
示例11: CmdTraceProc
internal CmdTraceProc(string cmd, TCL.VarFlag newFlags)
{
flags = newFlags;
command = cmd;
}
示例12: untraceVar
public void untraceVar( string part1, string part2, VarTrace trace, TCL.VarFlag flags )
// OR-ed collection of bits describing current
// trace, including any of TCL.VarFlag.TRACE_READS,
// TCL.VarFlag.TRACE_WRITES, TCL.VarFlag.TRACE_UNSETS,
// TCL.VarFlag.GLOBAL_ONLY and TCL.VarFlag.NAMESPACE_ONLY.
{
Var.untraceVar( this, part1, part2, flags, trace );
}
示例13: setVar
/// <summary> Set a variable.
///
/// </summary>
/// <param name="interp">the interp that holds the variable
/// </param>
/// <param name="name">name of the variable.
/// </param>
/// <param name="value">the new value for the variable
/// </param>
/// <param name="flags">misc flags that control the actions of this method
/// </param>
internal static TclObject setVar( Interp interp, string name, TclObject value, TCL.VarFlag flags )
{
return setVar( interp, name, null, value, flags );
}
示例14: incrVar
/// <summary> TclIncrVar2 -> incrVar
///
/// Given a two-part variable name, which may refer either to a scalar
/// variable or an element of an array, increment the Tcl object value
/// of the variable by a specified amount.
///
/// </summary>
/// <param name="part1">1st part of the variable name.
/// </param>
/// <param name="part2">2nd part of the variable name.
/// </param>
/// <param name="incrAmount">Amount to be added to variable.
/// </param>
/// <param name="flags">misc flags that control the actions of this method
///
/// Results:
/// Returns a reference to the TclObject holding the new value of the
/// variable. If the specified variable doesn't exist, or there is a
/// clash in array usage, or an error occurs while executing variable
/// traces, then a TclException will be raised.
///
/// Side effects:
/// The value of the given variable is incremented by the specified
/// amount. If either the array or the entry didn't exist then a new
/// variable is created. The ref count for the returned object is _not_
/// incremented to reflect the returned reference; if you want to keep a
/// reference to the object you must increment its ref count yourself.
///
/// ----------------------------------------------------------------------
/// </param>
internal static TclObject incrVar( Interp interp, TclObject part1, TclObject part2, int incrAmount, TCL.VarFlag flags )
{
TclObject varValue = null;
bool createdNewObj; // Set to true if var's value object is shared
// so we must increment a copy (i.e. copy
// on write).
int i;
bool err;
// There are two possible error conditions that depend on the setting of
// TCL.VarFlag.LEAVE_ERR_MSG. an exception could be raised or null could be returned
err = false;
try
{
varValue = getVar( interp, part1, part2, flags );
}
catch ( TclException e )
{
err = true;
throw;
}
finally
{
// FIXME : is this the correct way to catch the error?
if ( err || varValue == null )
interp.addErrorInfo( "\n (reading value of variable to increment)" );
}
// Increment the variable's value. If the object is unshared we can
// modify it directly, otherwise we must create a new copy to modify:
// this is "copy on write". Then free the variable's old string
// representation, if any, since it will no longer be valid.
createdNewObj = false;
if ( varValue.Shared )
{
varValue = varValue.duplicate();
createdNewObj = true;
}
try
{
i = TclInteger.get( interp, varValue );
}
catch ( TclException e )
{
if ( createdNewObj )
{
varValue.release(); // free unneeded copy
}
throw;
}
TclInteger.set( varValue, ( i + incrAmount ) );
// Store the variable's new value and run any write traces.
return setVar( interp, part1, part2, varValue, flags );
}
示例15: makeUpvar
/// <summary> MakeUpvar -> makeUpvar
///
/// Create a reference of a variable in otherFrame in the current
/// CallFrame, given a two-part name consisting of array name and
/// element within array.
///
/// </summary>
/// <param name="interp">Interp containing the variables
/// </param>
/// <param name="frame">CallFrame containing "other" variable.
/// null means use global context.
/// </param>
/// <param name="otherP1">the 1st part name of the variable in the "other" frame.
/// </param>
/// <param name="otherP2">the 2nd part name of the variable in the "other" frame.
/// </param>
/// <param name="otherFlags">the flags for scaope of "other" variable
/// </param>
/// <param name="myName">Name of scalar variable which will refer to otherP1/otherP2.
/// </param>
/// <param name="myFlags">only the TCL.VarFlag.GLOBAL_ONLY bit matters,
/// indicating the scope of myName.
/// </param>
/// <exception cref=""> TclException if the upvar cannot be created.
/// </exception>
protected internal static void makeUpvar( Interp interp, CallFrame frame, string otherP1, string otherP2, TCL.VarFlag otherFlags, string myName, TCL.VarFlag myFlags )
{
Var other, var, array;
Var[] result;
CallFrame varFrame;
CallFrame savedFrame = null;
Hashtable table;
NamespaceCmd.Namespace ns, altNs;
string tail;
bool newvar = false;
// Find "other" in "frame". If not looking up other in just the
// current namespace, temporarily replace the current var frame
// pointer in the interpreter in order to use TclLookupVar.
if ( ( otherFlags & TCL.VarFlag.NAMESPACE_ONLY ) == 0 )
{
savedFrame = interp.varFrame;
interp.varFrame = frame;
}
result = lookupVar( interp, otherP1, otherP2, ( otherFlags | TCL.VarFlag.LEAVE_ERR_MSG ), "access", true, true );
if ( ( otherFlags & TCL.VarFlag.NAMESPACE_ONLY ) == 0 )
{
interp.varFrame = savedFrame;
}
other = result[0];
array = result[1];
if ( other == null )
{
// FIXME : leave error message thing again
throw new TclRuntimeError( "unexpected null reference" );
}
// Now create a hashtable entry for "myName". Create it as either a
// namespace variable or as a local variable in a procedure call
// frame. Interpret myName as a namespace variable if:
// 1) so requested by a TCL.VarFlag.GLOBAL_ONLY or TCL.VarFlag.NAMESPACE_ONLY flag,
// 2) there is no active frame (we're at the global :: scope),
// 3) the active frame was pushed to define the namespace context
// for a "namespace eval" or "namespace inscope" command,
// 4) the name has namespace qualifiers ("::"s).
// If creating myName in the active procedure, look in its
// hashtable for runtime-created local variables. Create that
// procedure's local variable hashtable if necessary.
varFrame = interp.varFrame;
if ( ( ( myFlags & ( TCL.VarFlag.GLOBAL_ONLY | TCL.VarFlag.NAMESPACE_ONLY ) ) != 0 ) || ( varFrame == null ) || !varFrame.isProcCallFrame || ( myName.IndexOf( "::" ) != -1 ) )
{
// Java does not support passing an address so we pass
// an array of size 1 and then assign arr[0] to the value
NamespaceCmd.Namespace[] nsArr = new NamespaceCmd.Namespace[1];
NamespaceCmd.Namespace[] altNsArr = new NamespaceCmd.Namespace[1];
NamespaceCmd.Namespace[] dummyNsArr = new NamespaceCmd.Namespace[1];
string[] tailArr = new string[1];
NamespaceCmd.getNamespaceForQualName( interp, myName, null, myFlags, nsArr, altNsArr, dummyNsArr, tailArr );
// Get the values out of the arrays!
ns = nsArr[0];
altNs = altNsArr[0];
tail = tailArr[0];
if ( ns == null )
{
ns = altNs;
}
if ( ns == null )
{
throw new TclException( interp, "bad variable name \"" + myName + "\": unknown namespace" );
}
//.........这里部分代码省略.........