PikaScript
Classes | Public Types | Static Public Member Functions | List of all members
Pika::Script< Config > Struct Template Reference

Script is a meta-class that groups all the core classes of the PikaScript interpreter together (except for the value class). More...

#include <PikaScript.h>

Classes

class  BinaryFunctor
 See UnaryFunctor for documentation. More...
 
class  Frame
 The execution context and interpreter for PikaScript. More...
 
class  FullRoot
 FullRoot inherits from both Root and Config::Globals (which should be a descendant to Variable). More...
 
struct  lib
 
class  Native
 Native is the base class for the native functions and objects that can be accessed from PikaScript. More...
 
class  Root
 The Root is the first Frame you instantiate. More...
 
class  STLVariables
 STLVariables is the reference implementation of a variable space. More...
 
class  UnaryFunctor
 We provide two Native template classes for bridging PikaScript calls to C++ "functors". More...
 
class  Variables
 Variables is an abstract base class which implements the interface to the variable space that a Frame works on. More...
 

Public Types

typedef Config::Value Value
 The class used for all values and variables (defined by the configuration meta-class). E.g. STLValue.
 
typedef Value::String String
 The class used for strings (defined by the string class). E.g. std::string.
 
typedef String::value_type Char
 The character type for all strings (defined by the string class). E.g. char.
 
typedef String::size_type SizeType
 The length type for all strings (defined by the string class). E.g. size_t.
 
typedef String::const_iterator StringIt
 The const_iterator of the string is used so frequently it deserves its own typedef.
 
typedef Exception< StringXception
 The exception type.
 
typedef Config::Value Value
 The class used for all values and variables (defined by the configuration meta-class). E.g. STLValue.
 
typedef Value::String String
 The class used for strings (defined by the string class). E.g. std::string.
 
typedef String::value_type Char
 The character type for all strings (defined by the string class). E.g. char.
 
typedef String::size_type SizeType
 The length type for all strings (defined by the string class). E.g. size_t.
 
typedef String::const_iterator StringIt
 The const_iterator of the string is used so frequently it deserves its own typedef.
 
typedef Exception< StringXception
 The exception type.
 

Static Public Member Functions

template<class F >
static UnaryFunctor< F > * newUnaryFunctor (const F &f)
 Helper function to create a UnaryFunctor class with correct template parameters.
 
template<class F >
static BinaryFunctor< F > * newBinaryFunctor (const F &f)
 Helper function to create a BinaryFunctor class with correct template parameters.
 
static std::pair< Value, StringgetThisAndMethod (Frame &frame)
 getThisAndMethod splits the $callee variable of frame into object ("this") and method. More...
 
static Value getThis (Frame &frame)
 Returns only the "this" value as descripted in getThisAndMethod().
 
static Value getMethod (Frame &frame)
 Returns only the "method" value as descripted in getThisAndMethod().
 
static void addLibraryNatives (Frame &frame, bool includeIO=true)
 Registers the standard library native functions to frame. If includeIO is false, 'load', 'save', 'input', 'print' and 'system' will not be registered. Please, refer to the PikaScript standard library reference guide for more info on individual native functions.
 
template<class F >
static UnaryFunctor< F > * newUnaryFunctor (const F &f)
 Helper function to create a UnaryFunctor class with correct template parameters.
 
template<class F >
static BinaryFunctor< F > * newBinaryFunctor (const F &f)
 Helper function to create a BinaryFunctor class with correct template parameters.
 
static std::pair< Value, StringgetThisAndMethod (Frame &frame)
 getThisAndMethod splits the $callee variable of frame into object ("this") and method. More...
 
static Value getThis (Frame &frame)
 Returns only the "this" value as descripted in getThisAndMethod().
 
static Value getMethod (Frame &frame)
 Returns only the "method" value as descripted in getThisAndMethod().
 
static void addLibraryNatives (Frame &frame, bool includeIO=true)
 Registers the standard library native functions to frame. If includeIO is false, 'load', 'save', 'input', 'print' and 'system' will not be registered. Please, refer to the PikaScript standard library reference guide for more info on individual native functions.
 

Detailed Description

template<class Config>
struct Pika::Script< Config >

Script is a meta-class that groups all the core classes of the PikaScript interpreter together (except for the value class).

The benefit of having a class like this is that we can declare types that are common to all sub-classes.

The class is a template that takes another meta-class for configuring PikaScript. The configuration class should contain the following typedefs:

  1. Value (use this class for all PikaScript values, e.g. STLValue<std::string>)
  2. Locals (when a function call occurs, this sub-class of Variables will be instantiated for the callee)
  3. Globals (this sub-class of Variables is used for the FullRoot class)

Definition at line 266 of file PikaScript.h.

Member Function Documentation

template<class Config >
static std::pair<Value, String> Pika::Script< Config >::getThisAndMethod ( Frame frame)
static

getThisAndMethod splits the $callee variable of frame into object ("this") and method.

The returned value is a pair, where the first value ("this") is a reference to the object and the second value is the "method" name as a string.

Notice that if the $callee variable does not begin with a "frame specifier", it is assumed that the object belongs to the previous frame (e.g. the caller of the method). This holds true even if the method is actually defined in the root frame. For example

function { obj.meth() }

would trigger an error even if ::obj is defined since obj isn't defined in our function. While

function { ::obj.meth() }

works.

One common use for this function is in a PikaScript object constructor for extracting the "this" reference that should be constructed. Another situation where this routine is useful is if you use the "elevate" function to aggregate various methods into a single C++ function. You may then use this function to extract the method name.

template<class Config >
TMPL std::pair< T_TYPE(Value), T_TYPE(String)> Pika::Script< Config >::getThisAndMethod ( Frame frame)
static

getThisAndMethod splits the $callee variable of frame into object ("this") and method.

The returned value is a pair, where the first value ("this") is a reference to the object and the second value is the "method" name as a string.

Notice that if the $callee variable does not begin with a "frame specifier", it is assumed that the object belongs to the previous frame (e.g. the caller of the method). This holds true even if the method is actually defined in the root frame. For example

function { obj.meth() }

would trigger an error even if ::obj is defined since obj isn't defined in our function. While

function { ::obj.meth() }

works.

One common use for this function is in a PikaScript object constructor for extracting the "this" reference that should be constructed. Another situation where this routine is useful is if you use the "elevate" function to aggregate various methods into a single C++ function. You may then use this function to extract the method name.

Definition at line 854 of file PikaScriptImpl.h.


The documentation for this struct was generated from the following files: