PTLib
Version 2.14.3
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
script.h
Go to the documentation of this file.
1
/*
2
* script.h
3
*
4
* Abstract class for interface to external script languages
5
*
6
* Portable Tools Library
7
*
8
* Copyright (C) 2010 by Post Increment
9
*
10
* The contents of this file are subject to the Mozilla Public License
11
* Version 1.0 (the "License"); you may not use this file except in
12
* compliance with the License. You may obtain a copy of the License at
13
* http://www.mozilla.org/MPL/
14
*
15
* Software distributed under the License is distributed on an "AS IS"
16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17
* the License for the specific language governing rights and limitations
18
* under the License.
19
*
20
* The Original Code is Portable Tools Library.
21
*
22
* The Initial Developer of the Original Code is Post Increment
23
*
24
* Contributor(s): Craig Southeren
25
* Robert Jongbloed
26
*
27
* $Revision: 28224 $
28
* $Author: rjongbloed $
29
* $Date: 2012-08-21 18:09:25 +1000 (Tue, 21 Aug 2012) $
30
*/
31
32
#ifndef PTLIB_SCRIPT_H
33
#define PTLIB_SCRIPT_H
34
35
#ifdef P_USE_PRAGMA
36
#pragma interface
37
#endif
38
39
#include <
ptlib/pfactory.h
>
40
#include <
ptclib/vartype.h
>
41
42
44
47
class
PScriptLanguage
:
public
PObject
48
{
49
PCLASSINFO
(
PScriptLanguage
,
PObject
)
50
public
:
51
static
PScriptLanguage
*
Create
(
const
PString
& language);
52
57
PScriptLanguage
();
58
60
~PScriptLanguage
();
62
67
virtual
bool
LoadFile
(
68
const
PFilePath
& filename
69
) = 0;
70
73
virtual
bool
LoadText
(
74
const
PString
& text
75
) = 0;
76
79
virtual
bool
Load
(
80
const
PString
& script
81
);
82
89
virtual
bool
Run
(
90
const
char
* script = NULL
91
) = 0;
92
98
virtual
bool
CreateComposite
(
99
const
PString
& name
100
) = 0;
101
105
virtual
bool
GetVar
(
106
const
PString
& name,
107
PVarType
& var
108
) = 0;
109
113
virtual
bool
SetVar
(
114
const
PString
& name,
115
const
PVarType
& var
116
) = 0;
117
121
virtual
bool
GetBoolean
(
122
const
PString
& name
123
) = 0;
124
128
virtual
bool
SetBoolean
(
129
const
PString
& name,
130
bool
value
131
) = 0;
132
136
virtual
int
GetInteger
(
137
const
PString
& name
138
) = 0;
139
143
virtual
bool
SetInteger
(
144
const
PString
& name,
145
int
value
146
) = 0;
147
151
virtual
double
GetNumber
(
152
const
PString
& name
153
) = 0;
154
158
virtual
bool
SetNumber
(
159
const
PString
& name,
160
double
value
161
) = 0;
162
166
virtual
PString
GetString
(
167
const
PString
& name
168
) = 0;
169
173
virtual
bool
SetString
(
174
const
PString
& name,
175
const
char
* value
176
) = 0;
177
183
virtual
bool
ReleaseVariable
(
184
const
PString
& name
185
) = 0;
186
189
struct
ParamVector
:
public
vector<PVarType>
190
{
191
ParamVector
(
size_t
sz = 0) : vector<
PVarType
>(sz) { }
192
void
Push
(
void
* state);
193
void
Pop
(
void
* state);
194
};
195
197
struct
Signature
{
198
ParamVector
m_arguments
;
199
ParamVector
m_results
;
200
};
201
228
virtual
bool
Call
(
229
const
PString
& name,
230
const
char
* sigString = NULL,
231
...
232
) = 0;
233
virtual
bool
Call
(
234
const
PString
& name,
235
Signature
& signature
236
) = 0;
237
238
typedef
PNotifierTemplate<Signature &>
FunctionNotifier
;
239
#define PDECLARE_ScriptFunctionNotifier(cls, fn) PDECLARE_NOTIFIER2(PScriptLanguage, cls, fn, PScriptLanguage::Signature &)
240
244
virtual
bool
SetFunction
(
245
const
PString
& name,
246
const
FunctionNotifier
& func
247
) = 0;
249
252
253
__inline
bool
IsLoaded
()
const
{
return
m_loaded
; }
254
256
virtual
int
GetLastErrorCode
()
const
{
return
m_lastErrorCode
; }
257
259
virtual
const
PString
&
GetLastErrorText
()
const
{
return
m_lastErrorText
; }
261
262
protected
:
265
virtual
void
OnError
(
int
code,
const
PString
& str);
266
267
virtual
bool
InternalSetFunction
(
const
PString
& name,
const
FunctionNotifier
& func);
268
virtual
void
InternalRemoveFunction
(
const
PString
& prefix);
269
270
bool
m_loaded
;
271
int
m_lastErrorCode
;
272
PString
m_lastErrorText
;
273
typedef
map<PString, FunctionNotifier>
FunctionMap
;
274
FunctionMap
m_functions
;
275
276
PMutex
m_mutex
;
277
};
278
279
280
#if P_LUA
281
PFACTORY_LOAD
(PLua);
282
#endif
283
#if P_V8
284
PFACTORY_LOAD
(PJavaScript);
285
#endif
286
287
288
#endif // PTLIB_SCRIPT_H
289
include
ptclib
script.h
Generated on Fri Oct 10 2014 21:15:13 for PTLib by
1.8.3.1