PTLib
Version 2.18.8
|
A wrapper around a scripting language instance. More...
#include <script.h>
Classes | |
struct | ParamVector |
Individual Parameter in ParamVector. More... | |
struct | Signature |
Signature of Lua function and callback. More... | |
Public Member Functions | |
virtual void | OnError (int code, const PString &str) |
Set m_lastErrorCode and m_lastErrorText members, with mutex. More... | |
Construction | |
PScriptLanguage () | |
Create a context in which to execute a script. More... | |
~PScriptLanguage () | |
Destroy the script context. More... | |
member variables | |
__inline bool | IsLoaded () const |
Rerturn true if script is successfully loaded. More... | |
virtual int | GetLastErrorCode () const |
Get the last error text for an operation. More... | |
virtual const PString & | GetLastErrorText () const |
Get the last error text for an operation. More... | |
![]() | |
__inline unsigned | GetTraceContextIdentifier () const |
Get PTRACE context identifier. More... | |
__inline void | SetTraceContextIdentifier (unsigned id) |
__inline void | SetTraceContextIdentifier (const PObject &obj) |
__inline void | SetTraceContextIdentifier (const PObject *obj) |
__inline void | CopyTraceContextIdentifier (PObject &obj) const |
__inline void | CopyTraceContextIdentifier (PObject *obj) const |
virtual | ~PObject () |
__inline const char * | GetClass () const |
__inline bool | IsClass (const char *name) const |
__inline const PObject * | PTraceObjectInstance () const |
virtual PObject * | Clone () const |
Create a copy of the class on the heap. More... | |
template<class CLS > | |
CLS * | CloneAs () const |
As for Clone() but converts to specified type. More... | |
virtual PINDEX | HashFunction () const |
This function yields a hash value required by the PDictionary class. More... | |
virtual Comparison | Compare (const PObject &obj) const |
Compare the two objects and return their relative rank. More... | |
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
Determine the byte wise comparison of two objects. More... | |
bool | operator== (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator!= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator< (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator> (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator<= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator>= (const PObject &obj) const |
Compare the two objects. More... | |
virtual void | PrintOn (ostream &strm) const |
Output the contents of the object to the stream. More... | |
virtual void | ReadFrom (istream &strm) |
Input the contents of the object from the stream. More... | |
Static Public Member Functions | |
static PScriptLanguage * | Create (const PString &language) |
static PStringArray | GetLanguages () |
![]() | |
static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject *from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject *from) |
static __inline const char * | Class () |
static __inline const PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
template<typename T > | |
static Comparison | Compare2 (T v1, T v2) |
Compare two types, returning Comparison type. More... | |
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
Internal function caled from CompareObjectMemoryDirect() More... | |
Protected Types | |
typedef map< PString, FunctionNotifier > | FunctionMap |
Protected Member Functions | |
virtual bool | InternalSetFunction (const PString &name, const FunctionNotifier &func) |
virtual void | InternalRemoveFunction (const PString &prefix) |
PDECLARE_MUTEX (m_mutex) | |
![]() | |
PObject () | |
Constructor for PObject, made protected so cannot ever create one on its own. More... | |
Protected Attributes | |
bool | m_loaded |
int | m_lastErrorCode |
PString | m_lastErrorText |
FunctionMap | m_functions |
![]() | |
unsigned | m_traceContextIdentifier |
Scripting functions | |
typedef PNotifierTemplate < Signature & > | FunctionNotifier |
virtual PString | GetLanguageName () const =0 |
Get the name of this scripting language. More... | |
virtual bool | IsInitialised () const =0 |
Indicate language has initialised successfully. More... | |
virtual bool | LoadFile (const PFilePath &filename)=0 |
Load a script from a file. More... | |
virtual bool | LoadText (const PString &text)=0 |
Load script text. More... | |
virtual bool | Load (const PString &script) |
Load script from a file (if exists) or assume is the actual script. More... | |
virtual bool | Run (const char *script=NULL)=0 |
Run the script. More... | |
virtual bool | CreateComposite (const PString &name)=0 |
Create a composite structure. More... | |
virtual bool | GetVar (const PString &name, PVarType &var)=0 |
Get a variable in the script See class description for how name is parsed. More... | |
virtual bool | SetVar (const PString &name, const PVarType &var)=0 |
Set a variable in the script See class description for how name is parsed. More... | |
virtual bool | GetBoolean (const PString &name)=0 |
Get a variable in the script as a string value. More... | |
virtual bool | SetBoolean (const PString &name, bool value)=0 |
Set a variable in the script as a string value. More... | |
virtual int | GetInteger (const PString &name)=0 |
Get a variable in the script as an integer value. More... | |
virtual bool | SetInteger (const PString &name, int value)=0 |
Set a variable in the script as an integer value. More... | |
virtual double | GetNumber (const PString &name)=0 |
Get a variable in the script as a number value. More... | |
virtual bool | SetNumber (const PString &name, double value)=0 |
Set a variable in the script as a number value. More... | |
virtual PString | GetString (const PString &name)=0 |
Get a variable in the script as a string value. More... | |
virtual bool | SetString (const PString &name, const char *value)=0 |
Set a variable in the script as a string value. More... | |
virtual bool | ReleaseVariable (const PString &name)=0 |
Release a variable name. More... | |
virtual bool | Call (const PString &name, const char *sigString=NULL,...)=0 |
Call a specific function in the script. More... | |
virtual bool | Call (const PString &name, Signature &signature)=0 |
virtual bool | SetFunction (const PString &name, const FunctionNotifier &func)=0 |
Set a notifier as a script callable function. More... | |
A wrapper around a scripting language instance.
|
protected |
PScriptLanguage::PScriptLanguage | ( | ) |
Create a context in which to execute a script.
PScriptLanguage::~PScriptLanguage | ( | ) |
Destroy the script context.
|
pure virtual |
Call a specific function in the script.
The sigString
indicates the types of the arguments and return values for the function. The types available are: 'b' for boolean, 'i' for integer, 'n' for a number (double float) 's' for string (const char * or char *) 'p' for user defined (void *)
A '>' separates arguments from return values. The same letters are used for the tpes, but a pointer to the variable is supplied in the argument list, as for scanf. Note there can be multiple return values.
if 's' is used as a return value, then the caller is expected to delete the returned string pointer as it is allocated on the heap.
If sigString
is NULL or empty then a void parameterless function is called.
The second form with signature
alows for the caller to adaptively respond to different return types.
See class description for how name
is parsed.
name | Name of function to execute. |
sigString | Signature of arguments following |
name | Name of function to execute. |
signature | Signature of arguments following |
|
static |
|
pure virtual |
Create a composite structure.
The exact semantics is language dependant. For Lua this is a table.
See class description for how name
is parsed.
name | Name of new composite structure |
|
pure virtual |
Get a variable in the script as a string value.
See class description for how name
is parsed.
name | Name of global |
|
pure virtual |
Get a variable in the script as an integer value.
See class description for how name
is parsed.
name | Name of global |
|
pure virtual |
Get the name of this scripting language.
|
static |
|
inlinevirtual |
Get the last error text for an operation.
References m_lastErrorCode.
|
inlinevirtual |
Get the last error text for an operation.
References m_lastErrorText.
|
pure virtual |
Get a variable in the script as a number value.
See class description for how name
is parsed.
name | Name of global |
Get a variable in the script as a string value.
See class description for how name
is parsed.
name | Name of global |
|
pure virtual |
Get a variable in the script See class description for how name
is parsed.
name | Name of global |
|
protectedvirtual |
|
protectedvirtual |
|
pure virtual |
Indicate language has initialised successfully.
|
inline |
Rerturn true if script is successfully loaded.
|
virtual |
Load script from a file (if exists) or assume is the actual script.
script | Name of script file or script itself to load |
|
pure virtual |
Load a script from a file.
filename | Name of script file to load |
|
pure virtual |
Load script text.
text | Script text to load. |
|
virtual |
Set m_lastErrorCode and m_lastErrorText members, with mutex.
|
protected |
|
pure virtual |
Release a variable name.
Note the exact semantics is language dependant. It generally applies to global variables as most languages have automatic garbage collection for other variable types.
name | Name of table to delete |
|
pure virtual |
Run the script.
If script
is NULL or empty then the currently laoded script is executed. If script
is an existing file, then that will be loaded and executed. All other cases the string is loaded as direct script text and executed.
|
pure virtual |
Set a variable in the script as a string value.
See class description for how name
is parsed.
name | Name of global |
value | New value |
|
pure virtual |
Set a notifier as a script callable function.
See class description for how name
is parsed.
name | Name of function script can call |
func | Notifier excuted |
|
pure virtual |
Set a variable in the script as an integer value.
See class description for how name
is parsed.
name | Name of global |
value | New value |
|
pure virtual |
Set a variable in the script as a number value.
See class description for how name
is parsed.
name | Name of global |
value | New value |
|
pure virtual |
Set a variable in the script as a string value.
See class description for how name
is parsed.
name | Name of global |
value | New value |
|
pure virtual |
Set a variable in the script See class description for how name
is parsed.
name | Name of global |
|
protected |
|
protected |
Referenced by GetLastErrorCode().
|
protected |
Referenced by GetLastErrorText().
|
protected |