Class DynValue
A class representing a value in a Lua/MoonSharp script.
Inheritance
Inherited Members
Namespace: System.Dynamic.ExpandoObject
Assembly: cs.temp.dll.dll
Syntax
public sealed class DynValue
Properties
Boolean
Declaration
public bool Boolean { get; }
Property Value
|
System.Boolean
|
Callback
Gets the CLR callback (valid only if the Type is ClrFunction)
Declaration
public CallbackFunction Callback { get; }
Property Value
|
CallbackFunction
|
Coroutine
Gets the coroutine handle. (valid only if the Type is Thread).
Declaration
public Coroutine Coroutine { get; }
Property Value
|
Coroutine
|
False
A preinitialized, readonly instance, equaling False
Declaration
public static DynValue False { get; }
Property Value
|
DynValue
|
Function
Nil
A preinitialized, readonly instance, equaling Nil
Declaration
public static DynValue Nil { get; }
Property Value
|
DynValue
|
Number
Declaration
public double Number { get; }
Property Value
|
System.Double
|
ReadOnly
Returns true if this instance is write protected.
Declaration
public bool ReadOnly { get; }
Property Value
|
System.Boolean
|
ReferenceID
Gets a unique reference identifier. This is guaranteed to be unique only for dynvalues created in a single thread as it's not thread-safe.
Declaration
public int ReferenceID { get; }
Property Value
|
System.Int32
|
String
Declaration
public string String { get; }
Property Value
|
System.String
|
Table
TailCallData
Gets the tail call data.
Declaration
public TailCallData TailCallData { get; }
Property Value
|
TailCallData
|
True
A preinitialized, readonly instance, equaling True
Declaration
public static DynValue True { get; }
Property Value
|
DynValue
|
Tuple
Gets the values in the tuple (valid only if the Type is Tuple). This field is currently also used to hold arguments in values whose Type is TailCallRequest.
Declaration
public DynValue[] Tuple { get; }
Property Value
|
DynValue[]
|
Type
UserData
Void
A preinitialized, readonly instance, equaling Void
Declaration
public static DynValue Void { get; }
Property Value
|
DynValue
|
YieldRequest
Gets the yield request data.
Declaration
public YieldRequest YieldRequest { get; }
Property Value
|
YieldRequest
|
Methods
AsReadOnly()
Returns this value as readonly - eventually cloning it in the process if it isn't readonly to start with.
Declaration
public DynValue AsReadOnly()
Returns
|
DynValue
|
Assign(DynValue)
Performs an assignment, overwriting the value with the specified one.
Declaration
public void Assign(DynValue value)
Parameters
|
DynValue
value
The value. |
Exceptions
|
ScriptRuntimeException
If the value is readonly. |
CastToBool()
Casts this DynValue to a bool
Declaration
public bool CastToBool()
Returns
|
System.Boolean
False if value is false or nil, true otherwise. |
CastToNumber()
Casts this DynValue to a double, using coercion if the type is string.
Declaration
public double ? CastToNumber()
Returns
|
System.Nullable<System.Double>
The string representation, or null if not number, not string or non-convertible-string. |
CastToString()
Casts this DynValue to string, using coercion if the type is number.
Declaration
public string CastToString()
Returns
|
System.String
The string representation, or null if not number, not string. |
CheckType(String, DataType, Int32, TypeValidationFlags)
Checks the type of this value corresponds to the desired type. A propert ScriptRuntimeException is thrown if the value is not of the specified type or - considering the TypeValidationFlags - is not convertible to the specified type.
Declaration
public DynValue CheckType(string funcName, DataType desiredType, int argNum = -1, TypeValidationFlags flags = TypeValidationFlags.AutoConvert)
Parameters
|
System.String
funcName
Name of the function requesting the value, for error message purposes. |
|
DataType
desiredType
The desired data type. |
|
System.Int32
argNum
The argument number, for error message purposes. |
|
TypeValidationFlags
flags
The TypeValidationFlags. |
Returns
|
DynValue
|
Exceptions
|
ScriptRuntimeException
Thrown if the value is not of the specified type or - considering the TypeValidationFlags - is not convertible to the specified type. |
CheckUserDataType<T>(String, Int32, TypeValidationFlags)
Checks if the type is a specific userdata type, and returns it or throws.
Declaration
public T CheckUserDataType<T>(string funcName, int argNum = -1, TypeValidationFlags flags = TypeValidationFlags.AutoConvert)
Parameters
|
System.String
funcName
Name of the function. |
|
System.Int32
argNum
The argument number. |
|
TypeValidationFlags
flags
The flags. |
Returns
|
T
|
Type Parameters
|
T
|
Clone()
Clone(Boolean)
Clones this instance, overriding the "readonly" status.
Declaration
public DynValue Clone(bool readOnly)
Parameters
|
System.Boolean
readOnly
if set to |
Returns
|
DynValue
|
CloneAsWritable()
Clones this instance, returning a writable copy.
Declaration
public DynValue CloneAsWritable()
Returns
|
DynValue
|
Exceptions
|
System.ArgumentException
Can't clone Symbol values |
Equals(Object)
Determines whether the specified System.Object, is equal to this instance.
Declaration
public override bool Equals(object obj)
Parameters
|
System.Object
obj
The System.Object to compare with this instance. |
Returns
|
System.Boolean
|
Overrides
FromObject(Script, Object)
Creates a new DynValue from a CLR object
Declaration
public static DynValue FromObject(Script script, object obj)
Parameters
|
Script
script
The script. |
|
System.Object
obj
The object. |
Returns
|
DynValue
|
GetAsPrivateResource()
Returns this DynValue as an instance of IScriptPrivateResource, if possible, null otherwise
Declaration
public IScriptPrivateResource GetAsPrivateResource()
Returns
|
IScriptPrivateResource
False if value is false or nil, true otherwise. |
GetHashCode()
Returns a hash code for this instance.
Declaration
public override int GetHashCode()
Returns
|
System.Int32
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
Overrides
GetLength()
Gets the length of a string or table value.
Declaration
public DynValue GetLength()
Returns
|
DynValue
|
Exceptions
|
ScriptRuntimeException
Value is not a table or string. |
IsNil()
Determines whether this instance is nil or void
Declaration
public bool IsNil()
Returns
|
System.Boolean
|
IsNilOrNan()
Determines whether is nil, void or NaN (and thus unsuitable for using as a table key).
Declaration
public bool IsNilOrNan()
Returns
|
System.Boolean
|
IsNotNil()
Determines whether this instance is not nil or void
Declaration
public bool IsNotNil()
Returns
|
System.Boolean
|
IsNotVoid()
Determines whether this instance is not void
Declaration
public bool IsNotVoid()
Returns
|
System.Boolean
|
IsVoid()
Determines whether this instance is void
Declaration
public bool IsVoid()
Returns
|
System.Boolean
|
NewBoolean(Boolean)
Creates a new writable value initialized to the specified boolean.
Declaration
public static DynValue NewBoolean(bool v)
Parameters
|
System.Boolean
v
|
Returns
|
DynValue
|
NewCallback(Func<ScriptExecutionContext, CallbackArguments, DynValue>, String)
Creates a new writable value initialized to the specified CLR callback.
Declaration
public static DynValue NewCallback(Func<ScriptExecutionContext, CallbackArguments, DynValue> callBack, string name = null)
Parameters
|
Func<ScriptExecutionContext, CallbackArguments, DynValue>
callBack
|
|
System.String
name
|
Returns
|
DynValue
|
NewCallback(CallbackFunction)
Creates a new writable value initialized to the specified CLR callback. See also CallbackFunction.FromDelegate and CallbackFunction.FromMethodInfo factory methods.
Declaration
public static DynValue NewCallback(CallbackFunction function)
Parameters
|
CallbackFunction
function
|
Returns
|
DynValue
|
NewClosure(Closure)
Creates a new writable value initialized to the specified closure (function).
Declaration
public static DynValue NewClosure(Closure function)
Parameters
|
Closure
function
|
Returns
|
DynValue
|
NewCoroutine(Coroutine)
Creates a new writable value initialized to the specified coroutine. Internal use only, for external use, see Script.CoroutineCreate
Declaration
public static DynValue NewCoroutine(Coroutine coroutine)
Parameters
|
Coroutine
coroutine
The coroutine object. |
Returns
|
DynValue
|
NewNil()
Creates a new writable value initialized to Nil.
Declaration
public static DynValue NewNil()
Returns
|
DynValue
|
NewNumber(Double)
Creates a new writable value initialized to the specified number.
Declaration
public static DynValue NewNumber(double num)
Parameters
|
System.Double
num
|
Returns
|
DynValue
|
NewPrimeTable()
Creates a new writable value initialized to an empty prime table (a prime table is a table made only of numbers, strings, booleans and other prime tables).
Declaration
public static DynValue NewPrimeTable()
Returns
|
DynValue
|
NewString(StringBuilder)
Creates a new writable value initialized to the specified StringBuilder.
Declaration
public static DynValue NewString(StringBuilder sb)
Parameters
|
StringBuilder
sb
|
Returns
|
DynValue
|
NewString(String)
Creates a new writable value initialized to the specified string.
Declaration
public static DynValue NewString(string str)
Parameters
|
System.String
str
|
Returns
|
DynValue
|
NewString(String, Object[])
Creates a new writable value initialized to the specified string using String.Format like syntax
Declaration
public static DynValue NewString(string format, params object[] args)
Parameters
|
System.String
format
|
|
System.Object[]
args
|
Returns
|
DynValue
|
NewTable(Script)
Creates a new writable value initialized to an empty table.
Declaration
public static DynValue NewTable(Script script)
Parameters
|
Script
script
|
Returns
|
DynValue
|
NewTable(Script, DynValue[])
Creates a new writable value initialized to with array contents.
Declaration
public static DynValue NewTable(Script script, params DynValue[] arrayValues)
Parameters
|
Script
script
|
|
DynValue[]
arrayValues
|
Returns
|
DynValue
|
NewTable(Table)
Creates a new writable value initialized to the specified table.
Declaration
public static DynValue NewTable(Table table)
Parameters
|
Table
table
|
Returns
|
DynValue
|
NewTailCallReq(DynValue, DynValue[])
Creates a new request for a tail call. This is the preferred way to execute Lua/MoonSharp code from a callback, although it's not always possible to use it. When a function (callback or script closure) returns a TailCallRequest, the bytecode processor immediately executes the function contained in the request. By executing script in this way, a callback function ensures it's not on the stack anymore and thus a number of functionality (state savings, coroutines, etc) keeps working at full power.
Declaration
public static DynValue NewTailCallReq(DynValue tailFn, params DynValue[] args)
Parameters
|
DynValue
tailFn
The function to be called. |
|
DynValue[]
args
The arguments. |
Returns
|
DynValue
|
NewTailCallReq(TailCallData)
Creates a new request for a tail call. This is the preferred way to execute Lua/MoonSharp code from a callback, although it's not always possible to use it. When a function (callback or script closure) returns a TailCallRequest, the bytecode processor immediately executes the function contained in the request. By executing script in this way, a callback function ensures it's not on the stack anymore and thus a number of functionality (state savings, coroutines, etc) keeps working at full power.
Declaration
public static DynValue NewTailCallReq(TailCallData tailCallData)
Parameters
|
TailCallData
tailCallData
The data for the tail call. |
Returns
|
DynValue
|
NewTuple(DynValue[])
Creates a new tuple initialized to the specified values.
Declaration
public static DynValue NewTuple(params DynValue[] values)
Parameters
|
DynValue[]
values
|
Returns
|
DynValue
|
NewTupleNested(DynValue[])
Creates a new tuple initialized to the specified values - which can be potentially other tuples
Declaration
public static DynValue NewTupleNested(params DynValue[] values)
Parameters
|
DynValue[]
values
|
Returns
|
DynValue
|
NewUserData(UserData)
Creates a new userdata value
Declaration
public static DynValue NewUserData(UserData userData)
Parameters
|
UserData
userData
|
Returns
|
DynValue
|
NewYieldReq(DynValue[])
Creates a new request for a yield of the current coroutine.
Declaration
public static DynValue NewYieldReq(DynValue[] args)
Parameters
|
DynValue[]
args
The yield argumenst. |
Returns
|
DynValue
|
ToDebugPrintString()
Returns a string which is what it's expected to be output by debuggers.
Declaration
public string ToDebugPrintString()
Returns
|
System.String
|
ToObject()
Converts this MoonSharp DynValue to a CLR object.
Declaration
public object ToObject()
Returns
|
System.Object
|
ToObject(Type)
Converts this MoonSharp DynValue to a CLR object of the specified type.
Declaration
public object ToObject(Type desiredType)
Parameters
|
Type
desiredType
|
Returns
|
System.Object
|
ToObject<T>()
Converts this MoonSharp DynValue to a CLR object of the specified type.
Declaration
public T ToObject<T>()
Returns
|
T
|
Type Parameters
|
T
|
ToPrintString()
Returns a string which is what it's expected to be output by the print function applied to this value.
Declaration
public string ToPrintString()
Returns
|
System.String
|
ToScalar()
Converts a tuple to a scalar value. If it's already a scalar value, this function returns "this".
Declaration
public DynValue ToScalar()
Returns
|
DynValue
|
ToString()
Returns a System.String that represents this instance.
Declaration
public override string ToString()
Returns
|
System.String
A System.String that represents this instance. |