PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
PScriptLanguage Class Referenceabstract

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

`#include <script.h>`

Inheritance diagram for PScriptLanguage:
[legend]
Collaboration diagram for PScriptLanguage:
[legend]

## Classes
struct | ParamVector
| Individual Parameter in ParamVector. More...
struct | Signature
| Signature of Lua function and callback. More...

## Public Member Functions
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...
Public Member Functions inherited from PObject
unsigned | GetTraceContextIdentifier () const
| Get PTRACE context identifier. More...
void | SetTraceContextIdentifier (unsigned id)
void | GetTraceContextIdentifier (PObject &obj)
void | GetTraceContextIdentifier (PObject *obj)
void | SetTraceContextIdentifier (const PObject &obj)
void | SetTraceContextIdentifier (const PObject *obj)
virtual | ~PObject ()
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 const char * | GetClass (unsigned ancestor=0) const
| Get the current dynamic type of the object instance. More...
PBoolean | IsClass (const char *cls) const
virtual PBoolean | InternalIsDescendant (const char *clsName) const
| Determine if the dynamic type of the current instance is a descendent of the specified class. More...
__inline const PObject * | PTraceObjectInstance () const
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 Public Member Functions inherited from PObject
static const char * | Class ()
| Get the name of the class as a C string. More...
static __inline const PObject * | PTraceObjectInstance (const char *)
static __inline const PObject * | PTraceObjectInstance (const PObject *obj)
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 void | OnError (int code, const PString &str)
| Set m_lastErrorCode and m_lastErrorText members, with mutex. More...
virtual bool | InternalSetFunction (const PString &name, const FunctionNotifier &func)
virtual void | InternalRemoveFunction (const PString &prefix)
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
PMutex | m_mutex
Protected Attributes inherited from PObject
unsigned | m_traceContextIdentifier

## Path addition functions
typedef PNotifierTemplate < Signature & > | FunctionNotifier
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...

## Additional Inherited Members
Public Types inherited from PObject
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
| Result of the comparison operation performed by the `Compare()` function. More...
Friends inherited from PObject

## Detailed Description

A wrapper around a scripting language instance.

## Member Typedef Documentation

typedef map<PString, FunctionNotifier> PScriptLanguage::FunctionMap
| protected

typedef PNotifierTemplate<Signature &> PScriptLanguage::FunctionNotifier

## 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

  name | Name of function to execute.
  sigString | Signature of arguments following

virtual bool PScriptLanguage::Call | ( | const PString & | name,
|  | Signature & | signature
| ) |  |
| pure virtual

Parameters

  name | Name of function to execute.
  signature | Signature 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

  name | Name 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

  name | Name 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

  name | Name of global

virtual int PScriptLanguage::GetLastErrorCode | ( |  | ) | const
| inline virtual

Get the last error text for an operation.

References m_lastErrorCode.

virtual const PString& PScriptLanguage::GetLastErrorText | ( |  | ) | const
| inline virtual

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

  name | Name 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

  name | Name 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

  name | Name of global

virtual void PScriptLanguage::InternalRemoveFunction | ( | const PString & | prefix | ) |
| protected virtual

virtual bool PScriptLanguage::InternalSetFunction | ( | const PString & | name,
|  | const FunctionNotifier & | func
| ) |  |
| protected virtual

__inline bool PScriptLanguage::IsLoaded | ( |  | ) | const
| inline

Rerturn true if script is successfully loaded.

References m_loaded.

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

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

Parameters

  script | Name of script file or script itself to load

virtual bool PScriptLanguage::LoadFile | ( | const PFilePath & | filename | ) |
| pure virtual

Load a script from a file.

Parameters

  filename | Name of script file to load

virtual bool PScriptLanguage::LoadText | ( | const PString & | text | ) |
| pure virtual

Load script text.

Parameters

  text | Script text to load.

virtual void PScriptLanguage::OnError | ( | int | code,
|  | const PString & | str
| ) |  |
| protected virtual

Set m_lastErrorCode and m_lastErrorText members, with mutex.

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

  name | Name 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

  name | Name of global
  value | New 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

  name | Name of function script can call
  func | Notifier 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

  name | Name of global
  value | New 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

  name | Name of global
  value | New 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

  name | Name of global
  value | New 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

  name | Name 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

Referenced by IsLoaded().

PMutex PScriptLanguage::m_mutex
| protected

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

- script.h