ScriptFunction

This class encapsulates all types of script functions including native D functions and delegates. A native function must first be wrapped in this class before it can be given to a ScriptAny assignment. When an object is created with "new FunctionName()" its __proto__ is assigned to the function's "prototype" field. This allows OOP in the scripting language and is analogous to JavaScript.

Constructors

this
this(string fname, NativeFunction nfunc, bool isClass)

Constructs a new ScriptFunction out of a native D function.

this
this(string fname, NativeDelegate ndele, bool isClass)

Constructs a new ScriptFunction out of a native D delegate.

this
deprecated this(string fnname, string[] args, StatementNode[] statementNodes, Environment clos, bool isClass)

Constructor for creating script defined functions.

this
this(string fnname, string[] args, ubyte[] bc, bool isClass, bool isGenerator)

Constructor for functions created from compilation of statements.

Members

Enums

Type
enum Type

The type of function held by the object

Functions

argNames
auto argNames()

Property argNames. Note: native functions do not have this.

bind
void bind(ScriptAny thisObj)

Binds a specific this to be used no matter what. Internal users of ScriptFunction such as mildew.vm.virtualmachine.VirtualMachine must manually check the boundThis property and set this up. Unbinding is done by passing UNDEFINED as the parameter.

boundThis
ScriptAny boundThis()

bound this property. change with bind()

closure
auto closure()

Property get closure

compiled
ubyte[] compiled()

Compiled form cached

copyCompiled
ScriptFunction copyCompiled(Environment env, bool isClass)

Method to copy fresh compiled functions with the correct environment

functionName
auto functionName()

Returns the name of the function

functionName
auto functionName(string fnName)

Sets the function name

isClass
auto isClass()

Property isClass

isGenerator
bool isGenerator()

isGenerator property. used by various pieces

nativeDelegate
auto nativeDelegate()

get the delegate only if it is one

nativeFunction
auto nativeFunction()

get the native function ONLY if it is one

opCmp
int opCmp(ScriptFunction other)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(ScriptFunction other)
Undocumented in source. Be warned that the author may not have intended to support it.
statementNodes
auto statementNodes()

Property statementNodes

toHash
size_t toHash()
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()

Returns a string representing the type and name.

type
auto type()

Returns the type of function stored, such as native function, delegate, or script function

Static functions

emptyFunction
deprecated ScriptFunction emptyFunction(string name, bool isClass)

used by the parser for missing constructors in classes that don't extend

isInstanceOf
bool isInstanceOf(ScriptObject obj, ScriptFunction clazz)

Check if an object is an instance of a "class" constructor

Inherited Members

From ScriptObject

name
string name()

name property

getters
auto getters()

getters property

setters
auto setters()

setters property

prototype
auto prototype()

prototype property

prototype
auto prototype(ScriptObject proto)

prototype property (setter)

dictionary
auto dictionary()

This property provides direct access to the dictionary

addGetterProperty
void addGetterProperty(string propName, ScriptFunction getter)

Add a getter. Getters should be added to a constructor function's "prototype" field

addSetterProperty
void addSetterProperty(string propName, ScriptFunction setter)

Add a setter. Setters should be added to a constructor function's "prototype" field

lookupField
ScriptAny lookupField(string name)

Looks up a field through the prototype chain. Note that this does not call any getters because it is not possible to pass an Environment to opIndex.

opIndex
ScriptAny opIndex(string index)

Shorthand for lookupField.

assignField
ScriptAny assignField(string name, ScriptAny value)

Assigns a field to the current object. This does not call any setters.

hasGetter
bool hasGetter(string propName)

Determines if there is a getter for a given property

hasSetter
bool hasSetter(string propName)

Determines if there is a setter for a given property

findGetter
ScriptFunction findGetter(string propName)

Find a getter in the prototype chain

findSetter
ScriptFunction findSetter(string propName)

Find a setter in the prototype chain

opIndexAssign
ScriptAny opIndexAssign(T value, string index)

Shorthand for assignField

getOwnPropertyOrFieldDescriptor
ScriptObject getOwnPropertyOrFieldDescriptor(string propName)

Returns a property descriptor without searching the prototype chain. The object returned is an object possibly containing get, set, or value fields.

getOwnFieldOrPropertyDescriptors
ScriptObject getOwnFieldOrPropertyDescriptors()
Undocumented in source. Be warned that the author may not have intended to support it.
hasOwnFieldOrProperty
bool hasOwnFieldOrProperty(string propOrFieldName)

Tests whether or not a property or field exists in this object without searching the __proto__ chain.

nativeObject
T nativeObject()

If a native object was stored inside this ScriptObject, it can be retrieved with this function. Note that one must always check that the return value isn't null because all functions can be called with invalid "this" objects using functionName.call.

nativeObject
T nativeObject(T obj)

Native object can also be written because this is how binding works. Constructors receive a premade ScriptObject as the "this" with the name and prototype already set. Native D constructor functions have to set this property.

toString
string toString()

Returns a string with JSON like formatting representing the object's key-value pairs as well as any nested objects. In the future this will be replaced and an explicit function call will be required to print this detailed information.

_dictionary
ScriptAny[string] _dictionary;

The dictionary of key-value pairs

_getters
ScriptFunction[string] _getters;

The lookup table for getters

_setters
ScriptFunction[string] _setters;

The lookup table for setters

Meta