Class Script
This class implements a MoonSharp scripting session. Multiple Script objects can coexist in the same program but cannot share data among themselves unless some mechanism is put in place.
Inheritance
Inherited Members
Namespace: System.Dynamic.ExpandoObject
Assembly: cs.temp.dll.dll
Syntax
public class Script : IScriptPrivateResource
Constructors
Script()
Script(CoreModules)
Initializes a new instance of the Script class.
Declaration
public Script(CoreModules coreModules)
Parameters
|
CoreModules
coreModules
The core modules to be pre-registered in the default global table. |
Fields
LUA_VERSION
The Lua version being supported
Declaration
public const string LUA_VERSION = "5.2"
Field Value
|
System.String
|
VERSION
The version of the MoonSharp engine
Declaration
public const string VERSION = "2.0.0.0"
Field Value
|
System.String
|
Properties
DebuggerEnabled
Gets or sets a value indicating whether the debugger is enabled. Note that unless a debugger attached, this property returns a value which might not reflect the real status of the debugger. Use this property if you want to disable the debugger for some executions.
Declaration
public bool DebuggerEnabled { get; set; }
Property Value
|
System.Boolean
|
DefaultOptions
Gets or sets the script loader which will be used as the value of the ScriptLoader property for all newly created scripts.
Declaration
public static ScriptOptions DefaultOptions { get; }
Property Value
|
ScriptOptions
|
GlobalOptions
Gets the global options, that is options which cannot be customized per-script.
Declaration
public static ScriptGlobalOptions GlobalOptions { get; }
Property Value
|
ScriptGlobalOptions
|
Globals
Gets the default global table for this script. Unless a different table is intentionally passed (or setfenv has been used) execution uses this table.
Declaration
public Table Globals { get; }
Property Value
|
Table
|
Options
Gets access to the script options.
Declaration
public ScriptOptions Options { get; }
Property Value
|
ScriptOptions
|
PerformanceStats
Gets access to performance statistics.
Declaration
public PerformanceStatistics PerformanceStats { get; }
Property Value
|
PerformanceStatistics
|
Registry
MoonSharp (like Lua itself) provides a registry, a predefined table that can be used by any CLR code to store whatever Lua values it needs to store. Any CLR code can store data into this table, but it should take care to choose keys that are different from those used by other libraries, to avoid collisions. Typically, you should use as key a string GUID, a string containing your library name, or a userdata with the address of a CLR object in your code.
Declaration
public Table Registry { get; }
Property Value
|
Table
|
SourceCodeCount
Gets the source code count.
Declaration
public int SourceCodeCount { get; }
Property Value
|
System.Int32
The source code count. |
Methods
AttachDebugger(IDebugger)
Attaches a debugger. This usually should be called by the debugger itself and not by user code.
Declaration
public void AttachDebugger(IDebugger debugger)
Parameters
|
IDebugger
debugger
The debugger object. |
Call(DynValue)
Calls the specified function.
Declaration
public DynValue Call(DynValue function)
Parameters
|
DynValue
function
The Lua/MoonSharp function to be called |
Returns
|
DynValue
The return value(s) of the function call. |
Exceptions
|
System.ArgumentException
Thrown if function is not of DataType.Function |
Call(DynValue, DynValue[])
Calls the specified function.
Declaration
public DynValue Call(DynValue function, params DynValue[] args)
Parameters
|
DynValue
function
The Lua/MoonSharp function to be called |
|
DynValue[]
args
The arguments to pass to the function. |
Returns
|
DynValue
The return value(s) of the function call. |
Exceptions
|
System.ArgumentException
Thrown if function is not of DataType.Function |
Call(DynValue, Object[])
Calls the specified function.
Declaration
public DynValue Call(DynValue function, params object[] args)
Parameters
|
DynValue
function
The Lua/MoonSharp function to be called |
|
System.Object[]
args
The arguments to pass to the function. |
Returns
|
DynValue
The return value(s) of the function call. |
Exceptions
|
System.ArgumentException
Thrown if function is not of DataType.Function |
Call(Object)
Calls the specified function.
Declaration
public DynValue Call(object function)
Parameters
|
System.Object
function
The Lua/MoonSharp function to be called |
Returns
|
DynValue
|
Exceptions
|
System.ArgumentException
Thrown if function is not of DataType.Function |
Call(Object, Object[])
Calls the specified function.
Declaration
public DynValue Call(object function, params object[] args)
Parameters
|
System.Object
function
The Lua/MoonSharp function to be called |
|
System.Object[]
args
The arguments to pass to the function. |
Returns
|
DynValue
|
Exceptions
|
System.ArgumentException
Thrown if function is not of DataType.Function |
CreateConstantDynamicExpression(String, DynValue)
Creates a new dynamic expression which is actually quite static, returning always the same constant value.
Declaration
public DynamicExpression CreateConstantDynamicExpression(string code, DynValue constant)
Parameters
|
System.String
code
The code of the not-so-dynamic expression. |
|
DynValue
constant
The constant to return. |
Returns
|
DynamicExpression
|
CreateCoroutine(DynValue)
Creates a coroutine pointing at the specified function.
Declaration
public DynValue CreateCoroutine(DynValue function)
Parameters
|
DynValue
function
The function. |
Returns
|
DynValue
The coroutine handle. |
Exceptions
|
System.ArgumentException
Thrown if function is not of DataType.Function or DataType.ClrFunction |
CreateCoroutine(Object)
Creates a coroutine pointing at the specified function.
Declaration
public DynValue CreateCoroutine(object function)
Parameters
|
System.Object
function
The function. |
Returns
|
DynValue
The coroutine handle. |
Exceptions
|
System.ArgumentException
Thrown if function is not of DataType.Function or DataType.ClrFunction |
CreateDynamicExpression(String)
Creates a new dynamic expression.
Declaration
public DynamicExpression CreateDynamicExpression(string code)
Parameters
|
System.String
code
The code of the expression. |
Returns
|
DynamicExpression
|
DoString(String, Table, String)
Loads and executes a string containing a Lua/MoonSharp script.
Declaration
public DynValue DoString(string code, Table globalContext = null, string codeFriendlyName = null)
Parameters
|
System.String
code
The code. |
|
Table
globalContext
The global context. |
|
System.String
codeFriendlyName
Name of the code - used to report errors, etc. Also used by debuggers to locate the original source file. |
Returns
|
DynValue
A DynValue containing the result of the processing of the loaded chunk. |
GetBanner(String)
Gets a banner string with copyright info, link to website, version, etc.
Declaration
public static string GetBanner(string subproduct = null)
Parameters
|
System.String
subproduct
|
Returns
|
System.String
|
GetSourceCode(Int32)
Gets the source code.
Declaration
public SourceCode GetSourceCode(int sourceCodeID)
Parameters
|
System.Int32
sourceCodeID
The source code identifier. |
Returns
|
SourceCode
|
GetTypeMetatable(DataType)
Gets a type metatable.
Declaration
public Table GetTypeMetatable(DataType type)
Parameters
|
DataType
type
The type. |
Returns
|
Table
|
LoadFunction(String, Table, String)
Loads a string containing a Lua/MoonSharp function.
Declaration
public DynValue LoadFunction(string code, Table globalTable = null, string funcFriendlyName = null)
Parameters
|
System.String
code
The code. |
|
Table
globalTable
The global table to bind to this chunk. |
|
System.String
funcFriendlyName
Name of the function used to report errors, etc. |
Returns
|
DynValue
A DynValue containing a function which will execute the loaded code. |
LoadString(String, Table, String)
Loads a string containing a Lua/MoonSharp script.
Declaration
public DynValue LoadString(string code, Table globalTable = null, string codeFriendlyName = null)
Parameters
|
System.String
code
The code. |
|
Table
globalTable
The global table to bind to this chunk. |
|
System.String
codeFriendlyName
Name of the code - used to report errors, etc. Also used by debuggers to locate the original source file. |
Returns
|
DynValue
A DynValue containing a function which will execute the loaded code. |
RequireModule(String, Table)
Loads a module as per the "require" Lua function. http://www.lua.org/pil/8.1.html
Declaration
public DynValue RequireModule(string modname, Table globalContext = null)
Parameters
|
System.String
modname
The module name |
|
Table
globalContext
The global context. |
Returns
|
DynValue
|
Exceptions
|
ScriptRuntimeException
Raised if module is not found |
SetTypeMetatable(DataType, Table)
Sets a type metatable.
Declaration
public void SetTypeMetatable(DataType type, Table metatable)
Parameters
|
DataType
type
The type. Must be Nil, Boolean, Number, String or Function |
|
Table
metatable
The metatable. |
Exceptions
|
System.ArgumentException
Specified type not supported : + type.ToString() |
WarmUp()
Warms up the parser/lexer structures so that MoonSharp operations start faster.
Declaration
public static void WarmUp()