Context

Holds the variables and consts of a script stack frame. The global context can be accessed by climbing the Context.parent chain until reaching the Context whose parent is null. This allows native functions to define local and global variables. Note that calling a native function does not create a stack frame so one could write a native function that adds local variables to the stack frame where it was called.

Constructors

this
this(Context par, string nam)

Constructs a new Context.

this
this(Interpreter interpreter)

Constructs a global context

Members

Functions

declareVariableOrConst
bool declareVariableOrConst(string nam, ScriptAny value, bool isConst)

Attempt to declare and assign a new variable in the current context. Returns false if it already exists.

forceRemoveVarOrConst
void forceRemoveVarOrConst(string name)

Forces the removal of a const or variable in the current context.

forceSetVarOrConst
void forceSetVarOrConst(string name, ScriptAny value, bool isConst)

Force sets a variable or const no matter if the variable was declared already or is const. This is used by the host application to set globals or locals.

getGlobalContext
Context getGlobalContext()

climb context stack until finding one without a parent

insertLabel
void insertLabel(string label)

inserts a label into the list of valid labels

interpreter
Interpreter interpreter()

Retrieves the interpreter object from the top level context

labelExists
bool labelExists(string label)

checks context stack for a label

lookupVariableOrConst
ScriptAny* lookupVariableOrConst(string varName, bool isConst)

Attempts to look up existing variable or const throughout the stack. If found, returns a pointer to the variable location, and if it is const, sets isConst to true. Note, this pointer should not be stored by native functions because the variable table may be modified between function calls.

name
string name()

returns the name property of the Context

parent
Context parent()

returns the parent property

reassignVariable
ScriptAny* reassignVariable(string name, ScriptAny newValue, bool failedBecauseConst)

Attempts to reassign a variable anywhere in the stack and returns a pointer to the variable or null if the variable doesn't exist or is const. If the failure is due to const, failedBecauseConst is set to true. Note: this pointer should not be stored by native functions due to modifications to the variable table that may invalidate it and result in undefined behavior.

removeLabelFromCurrent
void removeLabelFromCurrent(string label)

removes a label from the existing context

toString
string toString()

Returns a string representing the type and name

unsetVariable
void unsetVariable(string name)

Removes a variable from anywhere on the Context stack it is located. This function cannot be used to unset consts.

variableOrConstExists
bool variableOrConstExists(string name)

Searches the entire Context stack for a variable starting with the current context and climbing the parent chain.

Meta