PikaScript
|
The Root is the first Frame you instantiate. More...
#include <PikaScript.h>
Public Member Functions | |
virtual void | trace (Frame &frame, const String &source, SizeType offset, bool lvalue, const Value &value, Precedence level, bool exit) |
Overload this member function if you want to customize the tracing mechanism in PikaScript. More... | |
virtual void | setTracer (Precedence traceLevel, const Value &tracerFunction) throw () |
Called by the standard library function "trace" to assign a PikaScript tracer function and a trace level. (Also called by the standard trace() on exceptions.) More... | |
bool | doTrace (Precedence level) const throw () |
String | generateLabel () |
Each "sub-frame" requires a unique "frame label". More... | |
virtual void | trace (Frame &frame, const String &source, SizeType offset, bool lvalue, const Value &value, Precedence level, bool exit) |
Overload this member function if you want to customize the tracing mechanism in PikaScript. More... | |
virtual void | setTracer (Precedence traceLevel, const Value &tracerFunction) throw () |
Called by the standard library function "trace" to assign a PikaScript tracer function and a trace level. (Also called by the standard trace() on exceptions.) More... | |
bool | doTrace (Precedence level) const throw () |
String | generateLabel () |
Each "sub-frame" requires a unique "frame label". More... | |
Public Member Functions inherited from Pika::Script< Config >::Frame | |
Frame (Variables &vars, Root &root, Frame *previous) | |
Constructs the Frame and associates it with the variable space vars . More... | |
Frame (Variables &vars, Root &root, Frame *previous) | |
Constructs the Frame and associates it with the variable space vars . More... | |
Variables & | getVariables () const throw () |
Returns a reference to the Variable instance associated with this Frame. Simple as that. | |
Root & | getRoot () const throw () |
Returns a reference to the "root frame" for this Frame. (No brainer.) | |
Frame & | getPrevious () const throw () |
Returns a reference to the previous frame (i.e. the frame of the caller of this frame). Must not be called on the root frame (will assert). | |
Variables & | getVariables () const throw () |
Returns a reference to the Variable instance associated with this Frame. Simple as that. | |
Root & | getRoot () const throw () |
Returns a reference to the "root frame" for this Frame. (No brainer.) | |
Frame & | getPrevious () const throw () |
Returns a reference to the previous frame (i.e. the frame of the caller of this frame). Must not be called on the root frame (will assert). | |
Value | get (const String &identifier, bool fallback=false) const |
Gets a variable value. More... | |
Value | getOptional (const String &identifier, const Value &defaultValue=Value()) const |
Tries to get the variable value as with get() (but never "falls back"). More... | |
const Value & | set (const String &identifier, const Value &v) |
Sets a variable value. More... | |
Value | reference (const String &identifier) const |
Creates a reference to the variable identified by identifier by prefixing it with a "frame label". More... | |
std::pair< Frame *, String > | resolveFrame (const String &identifier) const |
Resolves the frame for identifier and returns it together with identifier stripped of any prefixed "frame identifier". More... | |
Value | get (const String &identifier, bool fallback=false) const |
Gets a variable value. More... | |
Value | getOptional (const String &identifier, const Value &defaultValue=Value()) const |
Tries to get the variable value as with get() (but never "falls back"). More... | |
const Value & | set (const String &identifier, const Value &v) |
Sets a variable value. More... | |
Value | reference (const String &identifier) const |
Creates a reference to the variable identified by identifier by prefixing it with a "frame label". More... | |
std::pair< Frame *, String > | resolveFrame (const String &identifier) const |
Resolves the frame for identifier and returns it together with identifier stripped of any prefixed "frame identifier". More... | |
Value | call (const String &callee, const Value &body, long argc, const Value *argv=0) |
Calls a Pika function (by setting up a new "sub-frame" and executing the function body). More... | |
Value | execute (const String &body) |
A low-level function that executes body directly on the Frame instance. More... | |
Value | evaluate (const String source) |
Evaluates the PikaScript expression in source directly on this Frame. More... | |
StringIt | parse (const StringIt &begin, const StringIt &end, bool literal) |
Parses a PikaScript expression or literal (without evaluating it) and returns an iterator pointing at the end of the expression. | |
Value | call (const String &callee, const Value &body, long argc, const Value *argv=0) |
Calls a Pika function (by setting up a new "sub-frame" and executing the function body). More... | |
Value | execute (const String &body) |
A low-level function that executes body directly on the Frame instance. More... | |
Value | evaluate (const String source) |
Evaluates the PikaScript expression in source directly on this Frame. More... | |
StringIt | parse (const StringIt &begin, const StringIt &end, bool literal) |
Parses a PikaScript expression or literal (without evaluating it) and returns an iterator pointing at the end of the expression. | |
void | registerNative (const String &identifier, Native *native) |
Registers the native function (or object) native with identifier in the appropriate variable space (determined by any "frame identifier" present in identifier ). More... | |
template<class A0 , class R > | |
void | registerNative (const String &i, R(*f)(A0)) |
Helper template for easily registering a unary C++ function. More... | |
template<class A0 , class A1 , class R > | |
void | registerNative (const String &i, R(*f)(A0, A1)) |
Helper template for easily registering a binary C++ function. More... | |
template<class C , class A0 , class R > | |
void | registerNative (const String &i, C *o, R(C::*m)(A0)) |
Helper template for easily registering a unary C++ member function in the C++ object pointed to by o . More... | |
void | unregisterNative (const String &identifier) |
Helper function for unregistering a native function / object. More... | |
void | registerNative (const String &identifier, Native *native) |
Registers the native function (or object) native with identifier in the appropriate variable space (determined by any "frame identifier" present in identifier ). More... | |
template<class A0 , class R > | |
void | registerNative (const String &i, R(*f)(A0)) |
Helper template for easily registering a unary C++ function. More... | |
template<class A0 , class A1 , class R > | |
void | registerNative (const String &i, R(*f)(A0, A1)) |
Helper template for easily registering a binary C++ function. More... | |
template<class C , class A0 , class R > | |
void | registerNative (const String &i, C *o, R(C::*m)(A0)) |
Helper template for easily registering a unary C++ member function in the C++ object pointed to by o . More... | |
void | unregisterNative (const String &identifier) |
Helper function for unregistering a native function / object. More... | |
virtual | ~Frame () |
The default destructor does nothing, but it is always good practice to have a virtual destructor. | |
virtual | ~Frame () |
The default destructor does nothing, but it is always good practice to have a virtual destructor. | |
Protected Attributes | |
Precedence | traceLevel |
Calls to trace() will only happen when the "precedence level" is less or equal to this. More... | |
Value | tracerFunction |
Pika-script tracer function (used by the default trace() implementation). | |
bool | isInsideTracer |
Set to prevent recursive calling of tracer (used by the default trace() implementation). | |
Char | autoLabel [32] |
The last generated frame label (padded with leading ':'). | |
Char * | autoLabelStart |
The first character of the last generated frame label (begins at autoLabel + 30 and slowly moves backwards when necessary). | |
Additional Inherited Members | |
Protected Types inherited from Pika::Script< Config >::Frame | |
typedef std::pair< bool, Value > | XValue |
The XValue differentiates lvalues and rvalues and is used internally in the interpreter. More... | |
typedef std::pair< bool, Value > | XValue |
The XValue differentiates lvalues and rvalues and is used internally in the interpreter. More... | |
The Root is the first Frame you instantiate.
It is the starting point for the execution of PikaScript code. Its variables can be accessed from any frame with the special "frame identifier" ::. Furthermore, its variable space is often checked as a "backup" for symbols that cannot be retrieved from local "sub-frames".
The class also offers a few functions out of which you may overload trace() and setTracer() if you want to customize the tracing mechanism in PikaScript. The default implementation calls a PikaScript function that you can designate with the standard library function "trace".
In case you use PikaScript concurrently in different threads, you need a Root for every thread, but you could implement and share a sub-class of Variables that accesses shared data in a thread-safe manner.
If you just want to use the standard Root implementation with a standard variable space you may want to use FullRoot instead.
Definition at line 403 of file PikaScript.h.
|
inline |
This function is called a lot. For performance reasons it is good if it becomes inlined, so we are not declaring it virtual. If you want to customize which events that will be traced, try cleverly implementing your own trace() and setTracer() member functions instead.
Definition at line 408 of file PikaScript.h.
|
inline |
This function is called a lot. For performance reasons it is good if it becomes inlined, so we are not declaring it virtual. If you want to customize which events that will be traced, try cleverly implementing your own trace() and setTracer() member functions instead.
Definition at line 408 of file PikaScript.h.
String Pika::Script< Config >::Root::generateLabel | ( | ) |
Each "sub-frame" requires a unique "frame label".
This function creates it by "incrementing" Root::autoLabel, character by character, using '0' to '9' and upper and lower case 'a' to 'z', growing the string when necessary.
String Pika::Script< Config >::Root::generateLabel | ( | ) |
Each "sub-frame" requires a unique "frame label".
This function creates it by "incrementing" Root::autoLabel, character by character, using '0' to '9' and upper and lower case 'a' to 'z', growing the string when necessary.
|
virtual |
Called by the standard library function "trace" to assign a PikaScript tracer function and a trace level. (Also called by the standard trace() on exceptions.)
You may want to overload this member function if you change the tracing mechanism and need control over the trace level for example.
Definition at line 803 of file PikaScriptImpl.h.
|
virtual |
Called by the standard library function "trace" to assign a PikaScript tracer function and a trace level. (Also called by the standard trace() on exceptions.)
You may want to overload this member function if you change the tracing mechanism and need control over the trace level for example.
|
virtual |
Overload this member function if you want to customize the tracing mechanism in PikaScript.
The default implementation calls the PikaScript function Root::tracerFunction that you can assign with the standard library function "trace". See the standard library documentation on "trace" for more information on the arguments to this member function.
Definition at line 808 of file PikaScriptImpl.h.
|
virtual |
Overload this member function if you want to customize the tracing mechanism in PikaScript.
The default implementation calls the PikaScript function Root::tracerFunction that you can assign with the standard library function "trace". See the standard library documentation on "trace" for more information on the arguments to this member function.
|
protected |
Calls to trace() will only happen when the "precedence level" is less or equal to this.
E.g. if traceLevel is CALL, only function calls and caught exceptions will be traced.
Definition at line 410 of file PikaScript.h.