ScriptAny

This variant holds primitive values as well as ScriptObject derived complex reference types.

Constructors

this
this(T value)

Constructs a new ScriptAny based on the value given.

Members

Enums

Type
enum Type

Enumeration of what type is held by a ScriptAny. Note that a function, array, or string can be used as an object, so the best way to check if a ScriptAny is a ScriptObject is to use isObject.

Functions

addGetterProperty
void addGetterProperty(string name, ScriptFunction func)

Add a get method to an object

addSetterProperty
void addSetterProperty(string name, ScriptFunction func)

Add a set method to an object

assignField
ScriptAny assignField(T index, ScriptAny value, bool success)

Attempt to assign a field of a complex object. This can be used to assign array indexes if the index is a number.

assignField
ScriptAny assignField(T index, ScriptAny value)

Overload to ignore the bool

checkValue
T checkValue()

Converts a stored value back into a D value if it is valid, otherwise throws an exception.

isInteger
auto isInteger()

Returns true if the value stored is a valid integer, but not a floating point number.

isNativeObjectType
bool isNativeObjectType()

Shorthand for testing if this is a ScriptObject containing a native D object of a specific type.

isNull
auto isNull()

Returns true if the type is NULL or if it an object or function whose stored value is null. Note that the second condition should be impossible as receiving a null object value sets the type to NULL anyway.

isNumber
auto isNumber()

Returns true if the value stored is a numerical type or anything that can be converted into a valid number such as boolean, or even null, which gets converted to 0.

isObject
auto isObject()

This should always be used instead of checking type==OBJECT because ScriptFunction, ScriptArray, and ScriptString are valid subclasses of ScriptObject.

isUndefined
auto isUndefined()

Returns true if the type is UNDEFINED.

lookupField
ScriptAny lookupField(T index, bool success)

Depending on the type of index, if it is a string it accesses a field of the object, otherwise if it is numerical, attempts to access an index of an array object.

lookupField
ScriptAny lookupField(T index)

Overload to ignore the bool

opAssign
auto opAssign(T value)

Assigns a value.

opBinary
auto opBinary(ScriptAny rhs)

Implements binary math operations between two ScriptAnys and returns a ScriptAny. For certain operations that make no sense the result will be NaN or UNDEFINED. Addition involving any number of ScriptStrings will always coerce the values to string and perform a concatenation, as per DMildew language semantics.

opCast
T opCast()

opCast will now use toValue

opCmp
int opCmp(ScriptAny other)

The comparison operations.

opEquals
bool opEquals(ScriptAny other)

Tests for equality by casting similar types to the same type and comparing values. If the types are too different to do this, the result is false.

opIndex
ScriptAny opIndex(string index)

Shorthand to access fields of the complex object types

opIndexAssign
ScriptAny opIndexAssign(T value, string index)

Shorthand to assign fields of the complex object types

opUnary
auto opUnary()

Defines unary math operations for a ScriptAny.

orOp
ScriptAny orOp(ScriptAny other)

A method so that (undefined || 22) results in 22.

serialize
ubyte[] serialize()

convert a value to raw bytes. Only certain values can be converted. Throws exception if not possible

strictEquals
bool strictEquals(ScriptAny other)

This implements the '===' and '!==' operators. Objects must be exactly the same in type and value. This operator should not be used on numerical primitives because true === 1 will return false. Same with 1.0 === 1.

toHash
size_t toHash()

This allows ScriptAny to be used as a key index in a table, however the scripting language currently only uses strings. In the future a Map class will take advantage of this.

toNativeObject
T toNativeObject()

Shorthand for returning nativeObject from casting this to ScriptObject

toString
auto toString()

Returns a string representation of the stored value

toValue
T toValue()

Similar to checkValue except if the type is invalid and doesn't match the template type, a sane default value such as 0 or null is returned instead of throwing an exception.

type
auto type()

Returns the read-only type property. This should always be checked before using the toValue or checkValue template to retrieve the stored D value. Unless one is casting to primitives and does not care about the value being 0 or false.

typeToString
string typeToString()

For use with the scripting language's typeof operator

Static functions

deserialize
ScriptAny deserialize(ubyte[] stream)

read a ScriptAny from a stream of bytes. if invalid data, throws exception

Static variables

UNDEFINED
auto UNDEFINED;

This should always be used to return an undefined value.

Meta