PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
jscript.h
Go to the documentation of this file.
1 /*
2  * v8script.h
3  *
4  * Interface library for V8 Javascript interpreter
5  *
6  * Portable Tools Library
7  *
8  * Copyright (C) 2012 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  *
26  * $Revision: 31786 $
27  * $Author: rjongbloed $
28  * $Date: 2014-04-17 11:17:58 +1000 (Thu, 17 Apr 2014) $
29  */
30 
31 #ifndef PTLIB_V8SCRIPT_H
32 #define PTLIB_V8SCRIPT_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include <ptlib.h>
39 
40 #if P_V8
41 
42 #include <ptclib/script.h>
43 #include <ptclib/vartype.h>
44 
45 
47 
50 class PJavaScript : public PScriptLanguage
51 {
52  PCLASSINFO(PJavaScript, PScriptLanguage)
53 
54  public:
59  PJavaScript();
60 
62  ~PJavaScript();
64 
69  virtual bool LoadFile(
70  const PFilePath & filename
71  );
72 
75  virtual bool LoadText(
76  const PString & text
77  );
78 
85  virtual bool Run(
86  const char * script = NULL
87  );
88 
89 
93  virtual bool CreateComposite(
94  const PString & name
95  );
96 
100  virtual bool GetVar(
101  const PString & name,
102  PVarType & var
103  );
104 
108  virtual bool SetVar(
109  const PString & name,
110  const PVarType & var
111  );
112 
116  bool GetBoolean(
117  const PString & name
118  );
119 
123  bool SetBoolean(
124  const PString & name,
125  bool value
126  );
127 
131  int GetInteger(
132  const PString & name
133  );
134 
138  bool SetInteger(
139  const PString & name,
140  int value
141  );
142 
146  double GetNumber(
147  const PString & name
148  );
149 
153  bool SetNumber(
154  const PString & name,
155  double value
156  );
157 
161  PString GetString(
162  const PString & name
163  );
164 
168  bool SetString(
169  const PString & name,
170  const char * value
171  );
172 
175  virtual bool ReleaseVariable(
176  const PString & name
177  );
178 
205  bool Call(
206  const PString & name,
207  const char * sigString = NULL,
208  ...
209  );
210  bool Call(
211  const PString & name,
212  Signature & signature
213  );
214 
215 
219  bool SetFunction(
220  const PString & name,
221  const FunctionNotifier & func
222  );
224 
225  protected:
226  struct Private;
227  Private * m_private;
228  PString m_resultText;
229 };
230 
231 
232 #endif // P_V8
233 
234 #endif // PTLIB_V8SCRIPT_H
235