PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PScriptLanguage Class Referenceabstract

A wrapper around a scripting language instance. More...

#include <script.h>

Inheritance diagram for PScriptLanguage:
Collaboration diagram for PScriptLanguage:

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 PStringGetLastErrorText () const
 Get the last error text for an operation. More...
 
- Public Member Functions inherited from PObject
__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 PObjectPTraceObjectInstance () const
 
virtual PObjectClone () 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 PScriptLanguageCreate (const PString &language)
 
static PStringArray GetLanguages ()
 
- Static Public Member Functions inherited from PObject
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 PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (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)
 
- Protected Member Functions inherited from PObject
 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
 
- Protected Attributes inherited from PObject
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...
 

Detailed Description

A wrapper around a scripting language instance.

Member Typedef Documentation

Constructor & Destructor Documentation

PScriptLanguage::PScriptLanguage ( )

Create a context in which to execute a script.

PScriptLanguage::~PScriptLanguage ( )

Destroy the script context.

Member Function Documentation

virtual bool PScriptLanguage::Call ( const PString name,
const char *  sigString = NULL,
  ... 
)
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.

Returns
false if function does not exist.
Parameters
nameName of function to execute.
sigStringSignature of arguments following
virtual bool PScriptLanguage::Call ( const PString name,
Signature signature 
)
pure virtual
Parameters
nameName of function to execute.
signatureSignature of arguments following
static PScriptLanguage* PScriptLanguage::Create ( const PString language)
static
virtual bool PScriptLanguage::CreateComposite ( const PString name)
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.

Parameters
nameName of new composite structure
virtual bool PScriptLanguage::GetBoolean ( const PString name)
pure virtual

Get a variable in the script as a string value.

See class description for how name is parsed.

Parameters
nameName of global
virtual int PScriptLanguage::GetInteger ( const PString name)
pure virtual

Get a variable in the script as an integer value.

See class description for how name is parsed.

Parameters
nameName of global
virtual PString PScriptLanguage::GetLanguageName ( ) const
pure virtual

Get the name of this scripting language.

static PStringArray PScriptLanguage::GetLanguages ( )
static
virtual int PScriptLanguage::GetLastErrorCode ( ) const
inlinevirtual

Get the last error text for an operation.

References m_lastErrorCode.

virtual const PString& PScriptLanguage::GetLastErrorText ( ) const
inlinevirtual

Get the last error text for an operation.

References m_lastErrorText.

virtual double PScriptLanguage::GetNumber ( const PString name)
pure virtual

Get a variable in the script as a number value.

See class description for how name is parsed.

Parameters
nameName of global
virtual PString PScriptLanguage::GetString ( const PString name)
pure virtual

Get a variable in the script as a string value.

See class description for how name is parsed.

Parameters
nameName of global
virtual bool PScriptLanguage::GetVar ( const PString name,
PVarType &  var 
)
pure virtual

Get a variable in the script See class description for how name is parsed.

Parameters
nameName of global
virtual void PScriptLanguage::InternalRemoveFunction ( const PString prefix)
protectedvirtual
virtual bool PScriptLanguage::InternalSetFunction ( const PString name,
const FunctionNotifier func 
)
protectedvirtual
virtual bool PScriptLanguage::IsInitialised ( ) const
pure virtual

Indicate language has initialised successfully.

__inline bool PScriptLanguage::IsLoaded ( ) const
inline

Rerturn true if script is successfully loaded.

virtual bool PScriptLanguage::Load ( const PString script)
virtual

Load script from a file (if exists) or assume is the actual script.

Parameters
scriptName of script file or script itself to load
virtual bool PScriptLanguage::LoadFile ( const PFilePath filename)
pure virtual

Load a script from a file.

Parameters
filenameName of script file to load
virtual bool PScriptLanguage::LoadText ( const PString text)
pure virtual

Load script text.

Parameters
textScript text to load.
virtual void PScriptLanguage::OnError ( int  code,
const PString str 
)
virtual

Set m_lastErrorCode and m_lastErrorText members, with mutex.

PScriptLanguage::PDECLARE_MUTEX ( m_mutex  )
protected
virtual bool PScriptLanguage::ReleaseVariable ( const PString name)
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.

Parameters
nameName of table to delete
virtual bool PScriptLanguage::Run ( const char *  script = NULL)
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.

virtual bool PScriptLanguage::SetBoolean ( const PString name,
bool  value 
)
pure virtual

Set a variable in the script as a string value.

See class description for how name is parsed.

Parameters
nameName of global
valueNew value
virtual bool PScriptLanguage::SetFunction ( const PString name,
const FunctionNotifier func 
)
pure virtual

Set a notifier as a script callable function.

See class description for how name is parsed.

Parameters
nameName of function script can call
funcNotifier excuted
virtual bool PScriptLanguage::SetInteger ( const PString name,
int  value 
)
pure virtual

Set a variable in the script as an integer value.

See class description for how name is parsed.

Parameters
nameName of global
valueNew value
virtual bool PScriptLanguage::SetNumber ( const PString name,
double  value 
)
pure virtual

Set a variable in the script as a number value.

See class description for how name is parsed.

Parameters
nameName of global
valueNew value
virtual bool PScriptLanguage::SetString ( const PString name,
const char *  value 
)
pure virtual

Set a variable in the script as a string value.

See class description for how name is parsed.

Parameters
nameName of global
valueNew value
virtual bool PScriptLanguage::SetVar ( const PString name,
const PVarType &  var 
)
pure virtual

Set a variable in the script See class description for how name is parsed.

Parameters
nameName of global

Member Data Documentation

FunctionMap PScriptLanguage::m_functions
protected
int PScriptLanguage::m_lastErrorCode
protected

Referenced by GetLastErrorCode().

PString PScriptLanguage::m_lastErrorText
protected

Referenced by GetLastErrorText().

bool PScriptLanguage::m_loaded
protected

The documentation for this class was generated from the following file: