TorqueScript  0.2
Public Member Functions | Public Attributes | List of all members
TorqueScript::Interpreter Class Reference

The interpreter class represents a high level instance of the TorqueScript interpreter. It is where execution control flow begins. More...

#include <interpreter.hpp>

Collaboration diagram for TorqueScript::Interpreter:
Collaboration graph
[legend]

Public Member Functions

 Interpreter (const InterpreterConfiguration &config)
 Constructs a new interpreter with the specified configuration. More...
 
CodeBlockcompile (const std::string &input)
 Ask the interpreter to compile the input string and return the resulting CodeBlock. More...
 
void evaluate (const std::string &input, std::shared_ptr< ExecutionState > state=nullptr)
 
void execute (const std::string &path, std::shared_ptr< ExecutionState > state=nullptr)
 
std::shared_ptr< ExecutionStategetExecutionState ()
 
std::shared_ptr< ConsoleObjectinitializeConsoleObjectTree (ObjectInstantiationDescriptor &descriptor)
 Initializes the tree of objects described by the provided descriptor. More...
 
template<typename classType >
void registerConsoleObjectType ()
 
Global Variables

These functions handle getting and setting global variables within the context of an interpreter.

void setGlobal (const std::size_t name, StoredValue value)
 
void setGlobal (const std::string &name, StoredValue value)
 
StoredValuegetGlobal (const std::string &name)
 Retrieves a global variable by string. More...
 
StoredValuegetGlobal (const std::size_t name)
 Retrieves a global variable by string ID. More...
 
Functions

These functions handle management of functions registered in the interpreter.

void addFunction (std::shared_ptr< Function > function)
 Registers a new function to the interpreter. More...
 
std::shared_ptr< FunctiongetFunction (const std::string &space, const std::string &name)
 
std::shared_ptr< FunctiongetFunctionParent (Function *function)
 
FunctionRegistryfindFunctionRegistry (const std::string packageName)
 
void addFunctionRegistry (const std::string &packageName)
 
void activateFunctionRegistry (const std::string &packageName)
 
void deactivateFunctionRegistry (const std::string &packageName)
 
void removeFunctionRegistry (const std::string &packageName)
 

Public Attributes

ConsoleObjectRegistry mConsoleObjectRegistry
 The ConsoleObjectRegistry associated with this interpreter. It is used to store all ConsoleObject instances associated with the interpreter.
 
StringTable mStringTable
 The string table associated with this interpreter.
 
const InterpreterConfiguration mConfig
 The interpreter configuration.
 

Detailed Description

The interpreter class represents a high level instance of the TorqueScript interpreter. It is where execution control flow begins.

Examples
interpreterInit.cpp.

Constructor & Destructor Documentation

◆ Interpreter()

TorqueScript::Interpreter::Interpreter ( const InterpreterConfiguration config)

Constructs a new interpreter with the specified configuration.

Parameters
configThe configuration to initialize a new interpreter with.

Member Function Documentation

◆ addFunction()

void TorqueScript::Interpreter::addFunction ( std::shared_ptr< Function function)

Registers a new function to the interpreter.

Parameters
functionThe function object to register to the interpreter.

◆ compile()

CodeBlock* TorqueScript::Interpreter::compile ( const std::string &  input)

Ask the interpreter to compile the input string and return the resulting CodeBlock.

Parameters
inputThe string input containing the TorqueScript program.

◆ getGlobal() [1/2]

StoredValue* TorqueScript::Interpreter::getGlobal ( const std::size_t  name)

Retrieves a global variable by string ID.

Parameters
nameThe string ID representing the global variable name to lookup. This should be preferred over the lookup by name as this version will be faster.
Returns
The stored value at that global variable. If no such variable exists, nullptr is returned.

◆ getGlobal() [2/2]

StoredValue* TorqueScript::Interpreter::getGlobal ( const std::string &  name)

Retrieves a global variable by string.

Parameters
nameA string containining the name of the variable to retrieve, excluding the $ prefix.
Returns
The stored value at that global variable. If no such variable exists, nullptr is returned.

◆ initializeConsoleObjectTree()

std::shared_ptr<ConsoleObject> TorqueScript::Interpreter::initializeConsoleObjectTree ( ObjectInstantiationDescriptor descriptor)

Initializes the tree of objects described by the provided descriptor.

The tree described is walked and all objects along the tree will be initialized, unless any parent is invalid (Ie. bad typename, invalid parameters, etc) at which point that entire branch of the tree is invalidated and not instantiated.

Parameters
descriptorThe descriptor describing the root of the tree to initialize.
Returns
The root level ConsoleObject that was instantiated if successful. Otherwise, nullptr is returned.

The documentation for this class was generated from the following file: