PikaScript
PikaScript.h
1 
38 #ifndef PikaScript_h
39 #define PikaScript_h
40 
41 #include "assert.h" // Note: I always include assert.h like this so that you can override it with a "local" file.
42 #include <vector>
43 #include <map>
44 #include <string>
45 #include <functional>
46 
47 // These are defined as macros in the Windows headers and collide with some of our "proper" C++ definitions. Sorry, it
48 // just ain't right to use global macros in C++. I #undef them. Include PikaScript.h before the Windows headers if you
49 // need these macros (or push and pop their definitions before and after including this header with #pragma push_macro
50 // and pop_macro).
51 
52 #undef VOID
53 #undef ERROR
54 
58 namespace Pika {
59 
60 #if (PIKA_UNICODE)
61  #define STR(s) L##s
62  #define PIKA_SCRIPT_VERSION L"0.942"
63 #else
64  #define STR(x) x
65  #define PIKA_SCRIPT_VERSION "0.942"
66 #endif
67 
68 typedef unsigned char uchar;
69 typedef unsigned int uint;
70 typedef unsigned long ulong;
71 
82 
83 template<class S> std::string toStdString(const S& s);
84 template<class S> ulong hexToLong(typename S::const_iterator& p, const typename S::const_iterator& e);
85 template<class S> long stringToLong(typename S::const_iterator& p, const typename S::const_iterator& e);
86 template<class S, typename T> S intToString(T i, int radix = 10, int minLength = 1);
87 template<class S> double stringToDouble(typename S::const_iterator& p, const typename S::const_iterator& e);
88 template<class S> bool stringToDouble(const S& s, double& d);
89 template<class S> S doubleToString(double d, int precision = 14);
90 template<class S> S unescape(typename S::const_iterator& p, const typename S::const_iterator& e);
91 template<class S> S escape(const S& s);
92 
94 
102 template<class C, class A0, class R> class bound_mem_fun_t : public std::unary_function<A0, R> {
103  public: bound_mem_fun_t(R (C::*m)(A0), C* o) : m(m), o(o) { }
104  public: R operator()(A0 a) const { return (o->*m)(a); }
105  protected: R (C::*m)(A0);
106  protected: C* o;
107 };
108 
120 template<class C, class A0, class R> inline bound_mem_fun_t<C, A0, R> bound_mem_fun(R (C::*m)(A0), C* o) {
121  return bound_mem_fun_t<C, A0, R>(m, o);
122 }
123 
127 template<class T> class Dumb { };
128 
135 template<class S> class Exception : public std::exception {
136  public: Exception(const S& error) : error(error) { }
137  public: virtual S getError() const throw() { return error; }
138  public: virtual const char *what() const throw() { return (converted = toStdString(error)).c_str(); }
139  public: virtual ~Exception() throw() { } // (GCC requires explicit destructor with one that has throw().)
140  protected: S error;
141  protected: mutable std::string converted;
142 };
143 
173 template<class S> class STLValue : public S {
174 
176 
177  public: typedef S String;
178  public: typedef typename S::value_type Char;
179 
180 
182  public: STLValue() { }
183  public: STLValue(double d) : S(doubleToString<S>(d)) { }
184  public: STLValue(float f) : S(doubleToString<S>(f)) { }
185  public: STLValue(long i) : S(intToString<S, long>(i)) { }
186  public: STLValue(ulong i) : S(intToString<S, ulong>(i)) { }
187  public: STLValue(int i) : S(intToString<S, long>(i)) { }
188  public: STLValue(uint i) : S(intToString<S, ulong>(i)) { }
189  public: STLValue(bool b) : S(b ? S(STR("true")) : S(STR("false"))) { }
190  public: template<class T> STLValue(const T& s) : S(s) { }
191 
192 
194  public: operator bool() const;
195  public: operator long() const;
196  public: operator double() const;
197  public: operator float() const { return float(double(*this)); }
198  public: operator ulong() const { return ulong(long(*this)); }
199  public: operator int() const { return int(long(*this)); }
200  public: operator uint() const { return uint(int(*this)); }
201 
202 
204  public: bool operator<(const STLValue& r) const;
205  public: bool operator==(const STLValue& r) const;
206  public: bool operator!=(const STLValue& r) const { return !(*this == r); }
207  public: bool operator>(const STLValue& r) const { return r < (*this); }
208  public: bool operator<=(const STLValue& r) const { return !(r < (*this)); }
209  public: bool operator>=(const STLValue& r) const { return !((*this) < r); }
210  public: const STLValue operator[](const STLValue& i) const;
211 
212 
214  public: bool isVoid() const { return S::empty(); }
215 
216 
218  public: template<class T> bool operator<(const T& r) const { return operator<(STLValue(r)); }
219  public: template<class T> bool operator==(const T& r) const { return operator==(STLValue(r)); }
220  public: template<class T> bool operator!=(const T& r) const { return operator!=(STLValue(r)); }
221  public: template<class T> bool operator>(const T& r) const { return operator>(STLValue(r)); }
222  public: template<class T> bool operator<=(const T& r) const { return operator<=(STLValue(r)); }
223  public: template<class T> bool operator>=(const T& r) const { return operator>=(STLValue(r)); }
224  public: template<class T> const STLValue operator[](const T& i) const { return operator[](STLValue(i)); }
226 };
227 
230  NO_TRACE = 0
231  , TRACE_ERROR = 1
232  , TRACE_CALL = 2
233  , TRACE_LOOP = 3
234  , STATEMENT = 4
235  , BODY = 5
236  , ARGUMENT = 6
237  , BRACKETS = 7
238  , ASSIGN = 8
239  , LOGICAL_OR = 9
240  , LOGICAL_AND = 10
241  , BIT_OR = 11
242  , BIT_XOR = 12
243  , BIT_AND = 13
244  , EQUALITY = 14
245  , COMPARE = 15
246  , CONCAT = 16
247  , SHIFT = 17
248  , ADD_SUB = 18
249  , MUL_DIV = 19
250  , PREFIX = 20
251  , POSTFIX = 21
252  , DEFINITION = 22
253 };
254 
266 template<class Config> struct Script {
267 
268  typedef typename Config::Value Value;
269  typedef typename Value::String String;
270  typedef typename String::value_type Char;
271  typedef typename String::size_type SizeType;
272  typedef typename String::const_iterator StringIt;
274 
275  class Native;
276  class Root;
277 
291  class Variables {
292  public: typedef Script ForScript;
293  public: typedef std::vector< std::pair<String, Value> > VarList;
294  public: virtual bool lookup(const String& symbol, Value& result) = 0;
295  public: virtual bool assign(const String& symbol, const Value& value) = 0;
296  public: virtual bool erase(const String& symbol) = 0;
297  public: virtual void list(const String& key, VarList& list) = 0;
298  public: virtual Native* lookupNative(const String& identifier) = 0;
299  public: virtual bool assignNative(const String& identifier, Native* native) = 0;
300  public: virtual ~Variables();
301  };
302 
311  class Frame {
312 
314 
315  public: Frame(Variables& vars, Root& root, Frame* previous);
316 
317 
319  public: Variables& getVariables() const throw() { return vars; }
320  public: Root& getRoot() const throw() { return root; }
321  public: Frame& getPrevious() const throw() { assert(previous != 0); return *previous; }
322 
323 
325  public: Value get(const String& identifier, bool fallback = false) const;
326  public: Value getOptional(const String& identifier, const Value& defaultValue = Value()) const;
327  public: const Value& set(const String& identifier, const Value& v);
328  public: Value reference(const String& identifier) const;
329  public: std::pair< Frame*, String > resolveFrame(const String& identifier) const;
330 
331 
333  public: Value call(const String& callee, const Value& body, long argc, const Value* argv = 0);
334  public: Value execute(const String& body);
335  public: Value evaluate(const String source);
336  public: StringIt parse(const StringIt& begin, const StringIt& end, bool literal);
337 
338 
340  public: void registerNative(const String& identifier, Native* native);
341  public: template<class A0, class R> void registerNative(const String& i, R (*f)(A0)) {
342  registerNative(i, newUnaryFunctor(std::ptr_fun(f)));
343  }
344  public: template<class A0, class A1, class R> void registerNative(const String& i, R (*f)(A0, A1)) {
345  registerNative(i, newBinaryFunctor(std::ptr_fun(f)));
346  }
347  public: template<class C, class A0, class R> void registerNative(const String& i, C* o, R (C::*m)(A0)) {
349  }
350  public: void unregisterNative(const String& identifier) { registerNative(identifier, (Native*)(0)); }
351 
352 
354  public: virtual ~Frame() { }
355 
356  protected: typedef std::pair<bool, Value> XValue;
357  protected: void tick(const StringIt& p, const XValue& v, Precedence thres, bool exit);
358  protected: Value rvalue(const XValue& v, bool fallback = true);
359  protected: const Value& lvalue(const XValue& v);
360  protected: void white(StringIt& p, const StringIt& e);
361  protected: bool token(StringIt& p, const StringIt& e, const Char* token);
362  protected: Frame* resolveFrame(StringIt& p, const StringIt& e) const;
363  protected: template<class F> bool binaryOp(StringIt& p, const StringIt& e, XValue& v, bool dry
364  , Precedence thres, int hop, Precedence prec, F op);
365  protected: template<class F> bool assignableOp(StringIt& p, const StringIt& e, XValue& v, bool dry
366  , Precedence thres, int hop, Precedence prec, F op);
367  protected: template<class F> bool addSubOp(StringIt& p, const StringIt& e, XValue& v, bool dry
368  , Precedence thres, const F& f);
369  protected: template<class E, class I, class S> bool lgtOp(StringIt& p, const StringIt& e, XValue& v, bool dry
370  , Precedence thres, const E& excl, const I& incl, S shift);
371  protected: bool pre(StringIt& p, const StringIt& e, XValue& v, bool dry);
372  protected: bool post(StringIt& p, const StringIt& e, XValue& v, bool dry, Precedence thres);
373  protected: bool expr(StringIt& p, const StringIt& e, XValue& v, bool emptyOk, bool dry, Precedence thres);
374  protected: bool termExpr(StringIt& p, const StringIt& e, XValue& v, bool emptyOk, bool dry, Precedence thres
375  , Char term);
376 
377  protected: Variables& vars;
378  protected: Root& root;
379  protected: Frame* const previous;
380  protected: Frame* closure;
381  protected: const String* source;
382  protected: const String label;
383 
384  private: Frame(const Frame& copy); // N/A
385  private: Frame& operator=(const Frame& copy); // N/A
386  };
387 
403  class Root : public Frame {
404  public: Root(Variables& vars);
405  public: virtual void trace(Frame& frame, const String& source, SizeType offset, bool lvalue
406  , const Value& value, Precedence level, bool exit);
407  public: virtual void setTracer(Precedence traceLevel, const Value& tracerFunction) throw();
408  public: bool doTrace(Precedence level) const throw() { return level <= traceLevel; }
409  public: String generateLabel();
410  protected: Precedence traceLevel;
411  protected: Value tracerFunction;
412  protected: bool isInsideTracer;
413  protected: Char autoLabel[32];
414  protected: Char* autoLabelStart;
415  };
416 
422  class FullRoot : public Root, public Config::Globals {
423  public: FullRoot(bool includeIONatives = true) : Root(*(typename Config::Globals*)(this)) {
424  addLibraryNatives(*this, includeIONatives);
425  }
426  };
427 
435  class STLVariables : public Variables {
436  public: typedef std::map<const String, Value> VariableMap;
437  public: typedef std::map<const String, Native* > NativeMap;
438  public: virtual bool lookup(const String& symbol, Value& result);
439  public: virtual bool assign(const String& symbol, const Value& value) { vars[symbol] = value; return true; }
440  public: virtual bool erase(const String& symbol) { return (vars.erase(symbol) > 0); }
441  public: virtual void list(const String& key, typename Variables::VarList& list);
442  public: virtual Native* lookupNative(const String& name);
443  public: virtual bool assignNative(const String& name, Native* native);
444  public: virtual ~STLVariables();
445  public: VariableMap vars;
446  public: NativeMap natives;
447  };
448 
459  class Native {
460  public: virtual Value pikaCall(Frame& /*frame*/) { throw Xception(STR("Not callable")); }
461  public: virtual ~Native();
462  };
463 
484  template<class F, class A0 = typename F::argument_type, class R = typename F::result_type> class UnaryFunctor
485  : public Native {
486  public: UnaryFunctor(const F& functor) : func(functor) { }
487  protected: template<class T> const Value arg(Frame& f, const T&) { return f.get(STR("$0")); }
488  protected: Frame& arg(Frame& f, const Dumb<Frame&>&) { return f; }
489  protected: const Frame& arg(Frame& f, const Dumb<const Frame&>&) { return f; }
490  protected: template<class A, class T> Value call(A& a, const Dumb<T>&) { return func(a); }
491  protected: template<class A> Value call(A& a, const Dumb<void>&) { func(a); return Value(); }
492  public: virtual Value pikaCall(Frame& f) { return call(arg(f, Dumb<A0>()), Dumb<R>()); }
493  protected: F func;
494  };
495 
499  template<class F, class A0 = typename F::first_argument_type, class A1 = typename F::second_argument_type
500  , class R = typename F::result_type> class BinaryFunctor : public Native {
501  public: BinaryFunctor(const F& functor) : func(functor) { }
502  protected: template<class T> Value call(const Value& a0, const Value& a1, const T&) { return func(a0, a1); }
503  protected: Value call(const Value& a0, const Value& a1, const Dumb<void>&) { func(a0, a1); return Value(); }
504  public: virtual Value pikaCall(Frame& f) { return call(f.get(STR("$0")), f.get(STR("$1")), Dumb<R>()); }
505  protected: F func;
506  };
507 
508  template<class F> static UnaryFunctor<F>* newUnaryFunctor(const F& f) { return new UnaryFunctor<F>(f); }
509  template<class F> static BinaryFunctor<F>* newBinaryFunctor(const F& f) { return new BinaryFunctor<F>(f); }
510 
529  static std::pair<Value, String> getThisAndMethod(Frame& frame);
530  static Value getThis(Frame& frame) { return getThisAndMethod(frame).first; }
531  static Value getMethod(Frame& frame) { return getThisAndMethod(frame).second; }
532 
533  struct lib {
534  static Value elevate(Frame& frame);
535  static String character(double d);
536  static bool deleter(const Frame& frame);
537  static Value evaluate(const Frame& frame);
538  static bool exists(const Frame& frame);
539  static ulong find(const String& a, const String& b);
540  static void foreach(Frame& frame);
541  static String input(const String& prompt);
542  static Value invoke(Frame& frame);
543  static ulong length(const String& s);
544  static String load(const String& file);
545  static String lower(String s);
546  static ulong mismatch(const String& a, const String& b);
547  static uint ordinal(const String& s);
548  static ulong parse(Frame& frame);
549  static String precision(const Frame& frame);
550  static void print(const String& s);
551  static String radix(const Frame& frame);
552  static double random(double m);
553  static String reverse(String s);
554  static void save(const String& file, const String& chars);
555  static int system(const String& command);
556  static ulong search(const String& a, const String& b);
557  static ulong span(const String& a, const String& b);
558  static void thrower(const String& s);
559  static Value time(const Frame&);
560  static void trace(const Frame& frame);
561  static Value tryer(Frame& frame);
562  static String upper(String s);
563  };
564 
565  static void addLibraryNatives(Frame& frame, bool includeIO = true);
566 
567 }; // struct Script
568 
573 struct StdConfig {
574  typedef STLValue<std::string> Value;
575  typedef Script<StdConfig>::STLVariables Locals;
576  typedef Locals Globals;
577 };
578 
583 typedef Script<StdConfig> StdScript;
584 
585 #undef STR
586 
587 } // namespace Pika
588 
589 #endif
x=y x*=y x/=y x\=y x%=y x+=y x-=y x<<=y x>>=y x#=y x&=y x^=y x|=y
Definition: PikaScript.h:238
x===y x==y x!==y x!=y
Definition: PikaScript.h:244
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.
static Value getMethod(Frame &frame)
Returns only the "method" value as descripted in getThisAndMethod().
Definition: PikaScript.h:531
Value call(const Value &a0, const Value &a1, const T &)
Call the functor with the arguments a0 and a1.
Definition: PikaScript.h:502
Value call(A &a, const Dumb< void > &)
Overloaded to return the void value for functors that returns the void type.
Definition: PikaScript.h:491
Char * autoLabelStart
The first character of the last generated frame label (begins at autoLabel + 30 and slowly moves back...
Definition: PikaScript.h:414
Value call(A &a, const Dumb< T > &)
Call the functor with the argument a.
Definition: PikaScript.h:490
Frame & arg(Frame &f, const Dumb< Frame & > &)
Overloaded arg() that returns the actual frame instead of getting the argument value if the functor a...
Definition: PikaScript.h:488
String::value_type Char
The character type for all strings (defined by the string class). E.g. char.
Definition: PikaScript.h:270
virtual bool lookup(const String &symbol, Value &result)=0
Lookup symbol.
The PikaScript exception class.
Definition: PikaScript.h:135
Value getOptional(const String &identifier, const Value &defaultValue=Value()) const
Tries to get the variable value as with get() (but never "falls back").
virtual ~Variables()
Destructor.
Exception(const S &error)
Simply constructs the exception with error string error.
Definition: PikaScript.h:136
bool operator>=(const STLValue &r) const
Greater than or equal to comparison operator.
Definition: PikaScript.h:209
std::pair< bool, Value > XValue
The XValue differentiates lvalues and rvalues and is used internally in the interpreter.
Definition: PikaScript.h:356
S unescape(typename S::const_iterator &p, const typename S::const_iterator &e)
Converts a string that is either enclosed in single (' ') or double (" ") quotes. ...
String::const_iterator StringIt
The const_iterator of the string is used so frequently it deserves its own typedef.
Definition: PikaScript.h:272
FullRoot(bool includeIONatives=true)
Definition: PikaScript.h:423
We use this dummy class to specialize member functions for arbitrary types (including void...
Definition: PikaScript.h:127
STLValue(const T &s)
Pass other types of construction onwards to the super-class S.
Definition: PikaScript.h:190
bool operator<(const STLValue &r) const
Less than comparison operator.
Variables & getVariables() const
Returns a reference to the Variable instance associated with this Frame. Simple as that...
Definition: PikaScript.h:319
String generateLabel()
Each "sub-frame" requires a unique "frame label".
We provide two Native template classes for bridging PikaScript calls to C++ "functors".
Definition: PikaScript.h:484
S String
The class to use for all strings (i.e. the super-class).
Definition: PikaScript.h:177
bool operator>(const STLValue &r) const
Greater than comparison operator.
Definition: PikaScript.h:207
S error
The error string.
Definition: PikaScript.h:140
Value execute(const String &body)
A low-level function that executes body directly on the Frame instance.
Config::Value Value
The class used for all values and variables (defined by the configuration meta-class). E.g. STLValue.
Definition: PikaScript.h:268
std::pair< Frame *, String > resolveFrame(const String &identifier) const
Resolves the frame for identifier and returns it together with identifier stripped of any prefixed "f...
virtual const char * what() const
Returns the error as a null-terminated char string.
Definition: PikaScript.h:138
bool isVoid() const
Returns true if the value represents the empty string.
Definition: PikaScript.h:214
const Frame & arg(Frame &f, const Dumb< const Frame & > &)
Overloaded arg() that returns the actual frame instead of getting the argument value if the functor a...
Definition: PikaScript.h:489
STLValue(ulong i)
Constructs a value representing the ulong integer l.
Definition: PikaScript.h:186
xy x>=y
Definition: PikaScript.h:245
if () x, for () x
Definition: PikaScript.h:235
virtual bool assignNative(const String &identifier, Native *native)=0
Assign the native function (or object) native to identifier, replacing any already existing definitio...
The Root is the first Frame you instantiate.
Definition: PikaScript.h:403
Value call(const Value &a0, const Value &a1, const Dumb< void > &)
Overloaded to return the void value for functors that returns the void type.
Definition: PikaScript.h:503
S escape(const S &s)
Depending on the contents of the source string s it is encoded either in single (' ') or double (" ")...
void unregisterNative(const String &identifier)
Helper function for unregistering a native function / object.
Definition: PikaScript.h:350
void registerNative(const String &i, R(*f)(A0))
Helper template for easily registering a unary C++ function.
Definition: PikaScript.h:341
x*y x/y x xy
Definition: PikaScript.h:249
bool operator<=(const STLValue &r) const
Less than or equal to comparison operator.
Definition: PikaScript.h:208
Script< StdConfig > StdScript
This typedef exist for your convenience.
Definition: PikaScript.h:583
Precedence
Precedence levels are used both internally for the parser and externally for the tracing mechanism...
Definition: PikaScript.h:229
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...
Definition: PikaScript.h:347
virtual S getError() const
Return the error string for this exception.
Definition: PikaScript.h:137
(x) [x]
Definition: PikaScript.h:237
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...
virtual Value pikaCall(Frame &)
Process the PikaScript call.
Definition: PikaScript.h:460
Root & getRoot() const
Returns a reference to the "root frame" for this Frame. (No brainer.)
Definition: PikaScript.h:320
STLValue(uint i)
Constructs a value representing the unsigned integer i.
Definition: PikaScript.h:188
Value reference(const String &identifier) const
Creates a reference to the variable identified by identifier by prefixing it with a "frame label"...
x+y x-y
Definition: PikaScript.h:248
used only for tracing with tick()
Definition: PikaScript.h:230
S intToString(T i, int radix=10, int minLength=1)
Converts the integer i to a string with a radix and minimum length of your choice.
void registerNative(const String &identifier, Native *native)
Registers the native function (or object) native with identifier in the appropriate variable space (d...
See UnaryFunctor for documentation.
Definition: PikaScript.h:500
STLValue(float f)
Constructs a value representing the single precision floating point f.
Definition: PikaScript.h:184
double stringToDouble(typename S::const_iterator &p, const typename S::const_iterator &e)
Converts a string in scientific e notation (e.g. -12.34e-3) to a double floating point value...
STLValue()
The default constructor initializes the value to the empty string (or "void").
Definition: PikaScript.h:182
The execution context and interpreter for PikaScript.
Definition: PikaScript.h:311
ulong hexToLong(typename S::const_iterator &p, const typename S::const_iterator &e)
Converts a string in hexadecimal form to an ulong integer.
x() x.y x[y] x{y} x++ x–
Definition: PikaScript.h:251
static BinaryFunctor< F > * newBinaryFunctor(const F &f)
Helper function to create a BinaryFunctor class with correct template parameters. ...
Definition: PikaScript.h:509
Value::String String
The class used for strings (defined by the string class). E.g. std::string.
Definition: PikaScript.h:269
STLValue(long i)
Constructs a value representing the signed long integer l.
Definition: PikaScript.h:185
Value tracerFunction
Pika-script tracer function (used by the default trace() implementation).
Definition: PikaScript.h:411
const STLValue operator[](const STLValue &i) const
The subscript operator returns the concatenation of the value with the dot (.) separator (if necessar...
virtual bool assign(const String &symbol, const Value &value)=0
Assign value to symbol and return true if the assignment succeeded.
static Value getThis(Frame &frame)
Returns only the "this" value as descripted in getThisAndMethod().
Definition: PikaScript.h:530
function { }
Definition: PikaScript.h:252
String::size_type SizeType
The length type for all strings (defined by the string class). E.g. size_t.
Definition: PikaScript.h:271
void registerNative(const String &i, R(*f)(A0, A1))
Helper template for easily registering a binary C++ function.
Definition: PikaScript.h:344
Script is a meta-class that groups all the core classes of the PikaScript interpreter together (excep...
Definition: PikaScript.h:266
STLValue is the reference implementation of a PikaScript variable.
Definition: PikaScript.h:173
static std::pair< Value, String > getThisAndMethod(Frame &frame)
getThisAndMethod splits the $callee variable of frame into object ("this") and method.
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)...
Value evaluate(const String source)
Evaluates the PikaScript expression in source directly on this Frame.
Char autoLabel[32]
The last generated frame label (padded with leading ':').
Definition: PikaScript.h:413
bool operator==(const STLValue &r) const
Equality operator.
bound_mem_fun_t< C, A0, R > bound_mem_fun(R(C::*m)(A0), C *o)
bound_mem_fun creates a member functor bound to a specific C++ object through a pointer.
Definition: PikaScript.h:120
virtual Native * lookupNative(const String &identifier)=0
Lookup the native function (or object) with identifier.
S::value_type Char
The character type for all strings (e.g. char or wchar_t).
Definition: PikaScript.h:178
used only for tracing with tick()
Definition: PikaScript.h:233
Exception< String > Xception
The exception type.
Definition: PikaScript.h:273
STLValue(bool b)
Constructs a value representing the boolean b.
Definition: PikaScript.h:189
const Value & set(const String &identifier, const Value &v)
Sets a variable value.
static UnaryFunctor< F > * newUnaryFunctor(const F &f)
Helper function to create a UnaryFunctor class with correct template parameters.
Definition: PikaScript.h:508
bool isInsideTracer
Set to prevent recursive calling of tracer (used by the default trace() implementation).
Definition: PikaScript.h:412
std::string converted
Since what() is defined to return a pointer only, we need storage for the converted string within thi...
Definition: PikaScript.h:141
used only for tracing with tick()
Definition: PikaScript.h:232
virtual void list(const String &key, VarList &list)=0
Iterate all symbols that begins with key and push back names and values to list.
virtual ~Frame()
The default destructor does nothing, but it is always good practice to have a virtual destructor...
Definition: PikaScript.h:354
Native is the base class for the native functions and objects that can be accessed from PikaScript...
Definition: PikaScript.h:459
long stringToLong(typename S::const_iterator &p, const typename S::const_iterator &e)
Converts a string in decimal form to a signed long integer.
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.
bool doTrace(Precedence level) const
Definition: PikaScript.h:408
virtual void setTracer(Precedence traceLevel, const Value &tracerFunction)
Called by the standard library function "trace" to assign a PikaScript tracer function and a trace le...
Frame & getPrevious() const
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).
Definition: PikaScript.h:321
S doubleToString(double d, int precision=14)
Converts the double d to a string (in scientific e notation, e.g. -12.34e-3).
static Value elevate(Frame &frame)
Used to "aggregate" different method calls into a single function call.
Frame(Variables &vars, Root &root, Frame *previous)
Constructs the Frame and associates it with the variable space vars.
used only for tracing with tick()
Definition: PikaScript.h:231
Precedence traceLevel
Calls to trace() will only happen when the "precedence level" is less or equal to this...
Definition: PikaScript.h:410
virtual bool erase(const String &symbol)=0
Erase symbol. Return true if the symbol existed and was successfully erased.
bool operator!=(const STLValue &r) const
Non-equality operator.
Definition: PikaScript.h:206
Variables is an abstract base class which implements the interface to the variable space that a Frame...
Definition: PikaScript.h:291
const Value arg(Frame &f, const T &)
Get the first argument from the frame f.
Definition: PikaScript.h:487
STLValue(int i)
Constructs a value representing the signed integer i.
Definition: PikaScript.h:187
std::string toStdString(const S &s)
Converts the string s to a standard C++ string.
STLValue(double d)
Constructs a value representing the double precision floating point d.
Definition: PikaScript.h:183
@x !x ~x +x -x ++x –x
Definition: PikaScript.h:250