![]() |
Doomsday SDK
2.3
Core engine library and supporting libraries
|
Executes a script. More...
#include <process.h>
Classes | |
class | HangError |
Execution is taking too long to complete. More... | |
class | NotStoppedError |
The process is running while an operation is attempted that requires the process to be stopped. More... | |
class | SuspendError |
Suspending or resuming fails. More... | |
Public Types | |
enum | CallResult { IgnoreResult, TakeResult } |
using | Namespaces = Evaluator::Namespaces |
enum | State { Running, Suspended, Stopped } |
A process is always in one of these states. More... | |
Public Member Functions | |
Process (Record *externalGlobalNamespace=0) | |
Constructs a new process. More... | |
Process (Script const &script) | |
Constructs a new process. More... | |
void | call (Function const &function, ArrayValue const &arguments, Value *self=0) |
Performs a function call. More... | |
void | clear () |
Resets the process to an empty state. More... | |
Context & | context (duint downDepth=0) |
Return an execution context. More... | |
dsize | depth () const |
Determines the current depth of the call stack. More... | |
void | execute () |
Execute the next command(s) in the script. More... | |
void | finish (Value *returnValue=0) |
Finish the execution of the topmost context. More... | |
Record & | globals () |
Returns the global namespace of the process. More... | |
Record & | locals () |
Returns the local namespace of the process. More... | |
void | namespaces (Namespaces &spaces) const |
Collects the namespaces currently visible. More... | |
Context * | popContext () |
Pops the topmost context off the stack and returns it. More... | |
void | pushContext (Context *context) |
Pushes a new context to the process's stack. More... | |
void | run (Script const &script) |
Starts running the given script. More... | |
void | setWorkingPath (String const &newWorkingPath) |
Changes the working path of the process. More... | |
State | state () const |
void | stop () |
Stops the execution of the script. More... | |
void | suspend (bool suspended=true) |
Suspends or resumes execution of the script. More... | |
String const & | workingPath () const |
Returns the current working path. More... | |
Static Public Member Functions | |
template<typename... Args> | |
static Value * | scriptCall (CallResult result, Record &globals, String const &function, Args... args) |
Calls a script function. More... | |
template<typename ReturnValueType , typename... Args> | |
static ReturnValueType * | scriptCall (Record &globals, String const &function, Args... args) |
Executes a script.
The process maintains the execution environment, including things like local variables and keeping track of which statement is being executed.
enum de::Process::State |
A process is always in one of these states.
de::Process::Process | ( | Record * | externalGlobalNamespace = 0 | ) |
Constructs a new process.
The process is initialized to STOPPED state.
externalGlobalNamespace | Namespace to use as the global namespace of the process. If not specified, a private global namespace is created for the process. The process does not get ownership of the external global namespace. |
Definition at line 150 of file process.cpp.
de::Process::Process | ( | Script const & | script | ) |
Constructs a new process.
The process is initialized to RUNNING state.
script | Script to run. No reference to the script is retained apart from pointing to its statements. The script instance must remain in existence while the process is running, as it is the owner of the statements. |
Definition at line 158 of file process.cpp.
void de::Process::call | ( | Function const & | function, |
ArrayValue const & | arguments, | ||
Value * | self = 0 |
||
) |
Performs a function call.
A new context is created on the context stack and the function's statements are executed on the new stack. After the call is finished, the result value is pushed to the calling context's evaluator.
function | Function to call. |
arguments | Arguments for the function. The array's first element must be a DictionaryValue containing values for the named arguments of the call. The rest of the array are the unnamed arguments. |
self | Optional scope that becomes the value of the "self" variable. Ownership given to Process. |
Definition at line 351 of file process.cpp.
void de::Process::clear | ( | ) |
Resets the process to an empty state.
All existing content in the process's context stack is removed, leaving the process in a similar state than after construction.
Definition at line 171 of file process.cpp.
Return an execution context.
By default returns the topmost context.
downDepth | How many levels to go down. There are depth() levels in the context stack. |
Definition at line 285 of file process.cpp.
dsize de::Process::depth | ( | ) | const |
Determines the current depth of the call stack.
Definition at line 176 of file process.cpp.
void de::Process::execute | ( | ) |
Execute the next command(s) in the script.
Execution continues until the script leaves RUNNING state.
HangError | Execution takes too long. |
Definition at line 222 of file process.cpp.
void de::Process::finish | ( | Value * | returnValue = 0 | ) |
Finish the execution of the topmost context.
Execution will continue from the second topmost context.
returnValue | Value to use as the return value from the context. Takes ownership of the value. |
Definition at line 310 of file process.cpp.
Record & de::Process::globals | ( | ) |
Returns the global namespace of the process.
This is always the bottommost context in the stack.
Definition at line 436 of file process.cpp.
Record & de::Process::locals | ( | ) |
Returns the local namespace of the process.
This is always the topmost context in the stack.
Definition at line 450 of file process.cpp.
void de::Process::namespaces | ( | Namespaces & | spaces | ) | const |
Collects the namespaces currently visible.
This includes the process's own stack and the global namespaces.
spaces | The namespaces are collected here. The order is important: earlier namespaces shadow the subsequent ones. |
Definition at line 411 of file process.cpp.
Context * de::Process::popContext | ( | ) |
Pops the topmost context off the stack and returns it.
Ownership given to caller.
Definition at line 295 of file process.cpp.
void de::Process::pushContext | ( | Context * | context | ) |
Pushes a new context to the process's stack.
context | Context. Ownership taken. |
Definition at line 290 of file process.cpp.
void de::Process::run | ( | Script const & | script | ) |
Starts running the given script.
Note that the process must be in the FINISHED state for this to be a valid operation.
script | Script to run. No reference to the script is retained apart from pointing to its statements. The script instance must remain in existence while the process is running, as it is the owner of the statements. |
Definition at line 181 of file process.cpp.
|
inlinestatic |
Calls a script function.
Native arguments are converted to script source text and then parsed into Values when the call is executed.
Only non-named function arguments are supported by this method.
The namespace global may be modified if some of the argument values require variables, e.g., for refering Records. The created variables are named __argN__
, with N
being an increasing number.
result | What to do with the result value. |
globals | Global namespace where to execute the call. |
function | Name of the function. |
args | Argument values for the function call. |
void de::Process::setWorkingPath | ( | String const & | newWorkingPath | ) |
Changes the working path of the process.
File system access within the process is relative to the working path.
newWorkingPath | New working path for the process. |
Definition at line 346 of file process.cpp.
Process::State de::Process::state | ( | ) | const |
Definition at line 166 of file process.cpp.
void de::Process::stop | ( | ) |
Stops the execution of the script.
The process is set to the FINISHED state, which means it must be rerun with a new script.
Definition at line 200 of file process.cpp.
void de::Process::suspend | ( | bool | suspended = true | ) |
Suspends or resumes execution of the script.
Definition at line 189 of file process.cpp.
String const & de::Process::workingPath | ( | ) | const |
Returns the current working path.
Definition at line 341 of file process.cpp.