XSalScript
Namespace: PPJ.Runtime.XSal
Assembly: PPJ.Runtime.XSal.50 (5.0.0.0)
Compiles and executes XSal-compatible or C#-style scripts through a shared ScriptEngine.
- C#
- VB.NET
public class XSalScript
Public Class XSalScript
Example:
var script = new PPJ.Runtime.XSal.XSalScript("{ return 1 + 2; }");
string result = script.Run();
script.Dispose();
Constructors
XSalScript()
Initializes an empty script without compiling it.
XSalScript(source)
Initializes and compiles a nonempty script.
| Name | Type | Description |
|---|---|---|
| source | String | The source text; null or empty input creates an empty script. |
Properties
Context
Object: Gets or sets the object supplied as the script execution context.
CSharpSyntax
Boolean: Gets or sets whether new source bypasses legacy XSal syntax preprocessing.
Changing this flag does not recompile existing source.
DebugMode
Boolean: Gets or sets whether parser and interpreter errors are rethrown instead of recorded in LastError.
Handle
IntPtr: Gets a lazily allocated managed handle that keeps this script alive until Dispose releases it.
HasErrors
Boolean: Gets whether LastError contains a recorded compilation or execution error.
Interpreter
ScriptEngine: Gets or sets the shared script engine, creating one lazily when no engine is assigned.
LastError
String: Gets the last recorded parser or interpreter error, or null when the latest compilation or execution cleared it.
Source
String: Gets the stored source or preprocesses and compiles newly assigned nonempty source.
Text starting and ending with braces enables CSharpSyntax. Assigning null or empty text clears Source but does not discard an already compiled script.
Methods
AddLine(line)
Appends a source line and recompiles the accumulated script.
| Parameter | Type | Description |
|---|---|---|
| line | String | The line to append; legacy syntax is preprocessed unless CSharpSyntax is enabled. |
Returns: Boolean. True after successful compilation or for null or empty input; false after a recorded parser error.
Throws:
- ParserException Compilation fails while DebugMode is enabled.
Dispose()
Clears the execution context and releases the managed handle when allocated.
The stored source and compiled script remain available.
Finalize()
Destructor
FromHandle(handle)
Retrieves a script from a previously allocated managed handle.
| Parameter | Type | Description |
|---|---|---|
| handle | IntPtr | A live handle returned by Handle. |
Returns: XSalScript. The referenced script, or null for a nonpositive handle value.
Do not pass native window handles, arbitrary pointers, or handles already released by Dispose.
Run()
Executes the compiled script in the configured context.
Returns: String. The string form of the result, or an empty string for no compiled script, a null result, or a recorded interpreter error.
Throws:
- InterpreterException Execution fails while DebugMode is enabled.