PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lua.h
Go to the documentation of this file.
1 /*
2  * lua.h
3  *
4  * Interface library for Lua interpreter
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 
28 #ifndef PTLIB_LUA_H
29 #define PTLIB_LUA_H
30 
31 #ifdef P_USE_PRAGMA
32 #pragma interface
33 #endif
34 
35 #include <ptlib.h>
36 
37 #if P_LUA
38 
39 #include <ptclib/script.h>
40 #include <ptclib/vartype.h>
41 
42 
43 struct lua_State;
44 
45 
47 
56 class PLua : public PScriptLanguage
57 {
59  public:
64  PLua();
65 
67  ~PLua();
69 
72  static PString LanguageName();
74 
76  virtual PString GetLanguageName() const;
77 
79  virtual bool IsInitialised() const;
80 
83  virtual bool LoadFile(
84  const PFilePath & filename
85  );
86 
89  virtual bool LoadText(
90  const PString & text
91  );
92 
99  virtual bool Run(
100  const char * script = NULL
101  );
102 
108  bool CreateTable(
109  const PString & name,
110  const PString & metatable = PString::Empty()
111  );
112 
118  bool DeleteTable(
119  const PString & name,
120  bool metaTable = false
121  );
122 
123 
129  virtual bool CreateComposite(
130  const PString & name
131  );
132 
136  virtual bool GetVar(
137  const PString & name,
138  PVarType & var
139  );
140 
144  virtual bool SetVar(
145  const PString & name,
146  const PVarType & var
147  );
148 
152  bool GetBoolean(
153  const PString & name
154  );
155 
159  bool SetBoolean(
160  const PString & name,
161  bool value
162  );
163 
167  int GetInteger(
168  const PString & name
169  );
170 
174  bool SetInteger(
175  const PString & name,
176  int value
177  );
178 
182  double GetNumber(
183  const PString & name
184  );
185 
189  bool SetNumber(
190  const PString & name,
191  double value
192  );
193 
197  PString GetString(
198  const PString & name
199  );
200 
204  bool SetString(
205  const PString & name,
206  const char * value
207  );
208 
214  virtual bool ReleaseVariable(
215  const PString & name
216  );
217 
244  bool Call(
245  const PString & name,
246  const char * sigString = NULL,
247  ...
248  );
249  bool Call(
250  const PString & name,
251  Signature & signature
252  );
253 
254 
255  #define PDECLARE_LuaFunctionNotifier(cls, fn) PDECLARE_NOTIFIER2(PLua, cls, fn, PScriptLanguage::Signature &)
256 
260  bool SetFunction(
261  const PString & name,
262  const FunctionNotifier & func
263  );
265 
266  protected:
269  virtual bool OnLuaError(int code, const PString & str = PString::Empty(), int pop = 0);
270 
271  bool ParseVariableName(const PString & name, PStringArray & vars);
272  bool InternalGetVariable(const PString & name);
273  bool InternalSetVariable(const PString & name);
274  static int InternalCallback(lua_State * state);
275  int InternalCallback();
276 
277  lua_State * m_lua;
278 };
279 
280 
281 #endif // P_LUA
282 
283 #endif // PTLIB_LUA_H
284 
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
This is an array collection class of PString objects.
Definition: pstring.h:2365
virtual bool SetFunction(const PString &name, const FunctionNotifier &func)=0
Set a notifier as a script callable function.
The character string class.
Definition: pstring.h:108
static const PString & Empty()
Return an empty string.
A wrapper around a scripting language instance.
Definition: script.h:43