Otclient  14/8/2020
luainterface.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef LUAINTERFACE_H
24 #define LUAINTERFACE_H
25 
26 #include "declarations.h"
27 
28 struct lua_State;
29 typedef int (*LuaCFunction) (lua_State *L);
30 
33 {
34 public:
35  LuaInterface();
36  ~LuaInterface();
37 
38  void init();
39  void terminate();
40 
42  void registerFunctions();
43 
44  // functions that will register all script stuff in lua global environment
45  void registerSingletonClass(const std::string& className);
46  void registerClass(const std::string& className, const std::string& baseClass = "LuaObject");
47 
48  void registerClassStaticFunction(const std::string& className,
49  const std::string& functionName,
50  const LuaCppFunction& function);
51 
52  void registerClassMemberFunction(const std::string& className,
53  const std::string& functionName,
54  const LuaCppFunction& function);
55 
56  void registerClassMemberField(const std::string& className,
57  const std::string& field,
58  const LuaCppFunction& getFunction,
59  const LuaCppFunction& setFunction);
60 
61  void registerGlobalFunction(const std::string& functionName,
62  const LuaCppFunction& function);
63 
64  // register shortcuts using templates
65  template<class C, class B = LuaObject>
66  void registerClass() {
67  registerClass(stdext::demangle_class<C>(), stdext::demangle_class<B>());
68  }
69 
70  template<class C>
71  void registerClassStaticFunction(const std::string& functionName, const LuaCppFunction& function) {
72  registerClassStaticFunction(stdext::demangle_class<C>(), functionName, function);
73  }
74 
75  template<class C>
76  void registerClassMemberFunction(const std::string& functionName, const LuaCppFunction& function) {
77  registerClassMemberFunction(stdext::demangle_class<C>(), functionName, function);
78  }
79 
80  template<class C>
81  void registerClassMemberField(const std::string& field,
82  const LuaCppFunction& getFunction,
83  const LuaCppFunction& setFunction) {
84  registerClassMemberField(stdext::demangle_class<C>(), field, getFunction, setFunction);
85  }
86 
87  // methods for binding functions
88  template<class C, typename F>
89  void bindSingletonFunction(const std::string& functionName, F C::*function, C *instance);
90  template<class C, typename F>
91  void bindSingletonFunction(const std::string& className, const std::string& functionName, F C::*function, C *instance);
92 
93  template<class C, typename F>
94  void bindClassStaticFunction(const std::string& functionName, const F& function);
95  template<typename F>
96  void bindClassStaticFunction(const std::string& className, const std::string& functionName, const F& function);
97 
98  template<class C, typename F, class FC>
99  void bindClassMemberFunction(const std::string& functionName, F FC::*function);
100  template<class C, typename F, class FC>
101  void bindClassMemberFunction(const std::string& className, const std::string& functionName, F FC::*function);
102 
103  template<class C, typename F1, typename F2, class FC>
104  void bindClassMemberField(const std::string& fieldName, F1 FC::*getFunction, F2 FC::*setFunction);
105  template<class C, typename F1, typename F2, class FC>
106  void bindClassMemberField(const std::string& className, const std::string& fieldName, F1 FC::*getFunction, F2 FC::*setFunction);
107 
108  template<class C, typename F, class FC>
109  void bindClassMemberGetField(const std::string& fieldName, F FC::*getFunction);
110  template<class C, typename F, class FC>
111  void bindClassMemberGetField(const std::string& className, const std::string& fieldName, F FC::*getFunction);
112 
113  template<class C, typename F, class FC>
114  void bindClassMemberSetField(const std::string& fieldName, F FC::*setFunction);
115  template<class C, typename F, class FC>
116  void bindClassMemberSetField(const std::string& className, const std::string& fieldName, F FC::*setFunction);
117 
118  template<typename F>
119  void bindGlobalFunction(const std::string& functionName, const F& function);
120 
121 private:
123  static int luaObjectGetEvent(LuaInterface* lua);
125  static int luaObjectSetEvent(LuaInterface* lua);
127  static int luaObjectEqualEvent(LuaInterface* lua);
132  static int luaObjectCollectEvent(LuaInterface* lua);
133 
134 public:
136  bool safeRunScript(const std::string& fileName);
137 
140  void runScript(const std::string& fileName);
141 
144  void runBuffer(const std::string& buffer, const std::string& source);
145 
148  void loadScript(const std::string& fileName);
149 
152  void loadFunction(const std::string& buffer, const std::string& source = "lua function buffer");
153 
156  void evaluateExpression(const std::string& expression, const std::string& source = "lua expression");
157 
162  std::string traceback(const std::string& errorMessage = "", int level = 0);
163 
167  void throwError(const std::string& message);
168 
170  std::string getCurrentSourcePath(int level = 0);
171 
177  int safeCall(int numArgs = 0, int numRets = -1);
178 
183  int signalCall(int numArgs = 0, int numRets = -1);
184 
189  int newSandboxEnv();
190 
191  template<typename... T>
192  int luaCallGlobalField(const std::string& global, const std::string& field, const T&... args);
193 
194  template<typename... T>
195  void callGlobalField(const std::string& global, const std::string& field, const T&... args);
196 
197  template<typename R, typename... T>
198  R callGlobalField(const std::string& global, const std::string& field, const T&... args);
199 
200  bool isInCppCallback() { return m_cppCallbackDepth != 0; }
201 
202 private:
204  static int luaScriptLoader(lua_State* L);
206  static int lua_dofile(lua_State* L);
208  static int lua_dofiles(lua_State* L);
210  static int lua_loadfile(lua_State* L);
212  static int luaErrorHandler(lua_State* L);
214  static int luaCppFunctionCallback(lua_State* L);
216  static int luaCollectCppFunction(lua_State* L);
217 
218 public:
219  void createLuaState();
220  void closeLuaState();
221 
222  void collectGarbage();
223 
224  void loadBuffer(const std::string& buffer, const std::string& source);
225 
226  int pcall(int numArgs = 0, int numRets = 0, int errorFuncIndex = 0);
227  void call(int numArgs = 0, int numRets = 0);
228  void error();
229 
230  int ref();
231  int weakRef();
232  void unref(int ref);
233  void useValue() { pushValue(); ref(); }
234 
235  const char* typeName(int index = -1);
236  std::string functionSourcePath();
237 
238  void insert(int index);
239  void remove(int index);
240  bool next(int index = -2);
241 
242  void checkStack() { assert(getTop() <= 20); }
243  void getStackFunction(int level = 0);
244 
245  void getRef(int ref);
246  void getWeakRef(int weakRef);
247 
248  int getGlobalEnvironment() { return m_globalEnv; }
249  void setGlobalEnvironment(int env);
251 
252  void setMetatable(int index = -2);
253  void getMetatable(int index = -1);
254 
255  void getField(const char* key, int index = -1);
256  void getField(const std::string& key, int index = -1) { return getField(key.c_str(), index); }
257  void setField(const char* key, int index = -2);
258  void setField(const std::string& key, int index = -2) { return setField(key.c_str(), index); }
259 
260  void getTable(int index = -2);
261  void setTable(int index = -3);
262  void clearTable(int index = -1);
263 
264  void getEnv(int index = -1);
265  void setEnv(int index = -2);
266 
267  void getGlobal(const std::string& key);
268  void getGlobalField(const std::string& globalKey, const std::string& fieldKey);
269  void setGlobal(const std::string& key);
270 
271  void rawGet(int index = -1);
272  void rawGeti(int n, int index = -1);
273  void rawSet(int index = -3);
274  void rawSeti(int n, int index = -2);
275 
276  void newTable();
277  void createTable(int narr, int nrec);
278  void* newUserdata(int size);
279 
280  void pop(int n = 1);
281  long popInteger();
282  double popNumber();
283  bool popBoolean();
284  std::string popString();
285  void* popUserdata();
286  void* popUpvalueUserdata();
288 
289  void pushNil();
290  void pushInteger(long v);
291  void pushNumber(double v);
292  void pushBoolean(bool v);
293  void pushCString(const char* v);
294  void pushString(const std::string& v);
295  void pushLightUserdata(void* p);
296  void pushThread();
297  void pushValue(int index = -1);
298  void pushObject(const LuaObjectPtr& obj);
299  void pushCFunction(LuaCFunction func, int n = 0);
300  void pushCppFunction(const LuaCppFunction& func);
301 
302  bool isNil(int index = -1);
303  bool isBoolean(int index = -1);
304  bool isNumber(int index = -1);
305  bool isString(int index = -1);
306  bool isTable(int index = -1);
307  bool isFunction(int index = -1);
308  bool isCFunction(int index = -1);
309  bool isLuaFunction(int index = -1) { return (isFunction(index) && !isCFunction(index)); }
310  bool isUserdata(int index = -1);
311 
312  bool toBoolean(int index = -1);
313  int toInteger(int index = -1);
314  double toNumber(int index = -1);
315  const char* toCString(int index = -1);
316  std::string toString(int index = -1);
317  void* toUserdata(int index = -1);
318  LuaObjectPtr toObject(int index = -1);
319 
320  int getTop();
321  int stackSize() { return getTop(); }
322  void clearStack() { pop(stackSize()); }
323  bool hasIndex(int index) { return (stackSize() >= (index < 0 ? -index : index) && index != 0); }
324 
325  void loadFiles(std::string directory, bool recursive = false, std::string contains = "");
326 
328  template<typename T, typename... Args>
329  int polymorphicPush(const T& v, const Args&... args);
330  int polymorphicPush() { return 0; }
331 
334  template<class T>
335  T castValue(int index = -1);
336 
338  template<class T>
339  T polymorphicPop() { T v = castValue<T>(); pop(1); return v; }
340 
341 private:
342  lua_State* L;
343  int m_weakTableRef;
344  int m_cppCallbackDepth;
345  int m_totalObjRefs;
346  int m_totalFuncRefs;
347  int m_globalEnv;
348 };
349 
350 extern LuaInterface g_lua;
351 
352 // must be included after, because they need LuaInterface fully declared
353 #include "luaexception.h"
354 #include "luabinder.h"
355 #include "luavaluecasts.h"
356 
357 template<typename T, typename... Args>
358 int LuaInterface::polymorphicPush(const T& v, const Args&... args) {
359  int r = push_luavalue(v);
360  return r + polymorphicPush(args...);
361 }
362 
363 // next templates must be defined after above includes
364 
365 template<class C, typename F>
366 void LuaInterface::bindSingletonFunction(const std::string& functionName, F C::*function, C *instance) {
367  registerClassStaticFunction<C>(functionName, luabinder::bind_singleton_mem_fun(function, instance));
368 }
369 
370 template<class C, typename F>
371 void LuaInterface::bindSingletonFunction(const std::string& className, const std::string& functionName, F C::*function, C *instance) {
372  registerClassStaticFunction(className, functionName, luabinder::bind_singleton_mem_fun(function, instance));
373 }
374 
375 template<class C, typename F>
376 void LuaInterface::bindClassStaticFunction(const std::string& functionName, const F& function) {
377  registerClassStaticFunction<C>(functionName, luabinder::bind_fun(function));
378 }
379 template<typename F>
380 void LuaInterface::bindClassStaticFunction(const std::string& className, const std::string& functionName, const F& function) {
381  registerClassStaticFunction(className, functionName, luabinder::bind_fun(function));
382 }
383 
384 template<class C, typename F, class FC>
385 void LuaInterface::bindClassMemberFunction(const std::string& functionName, F FC::*function) {
386  registerClassMemberFunction<C>(functionName, luabinder::bind_mem_fun<C>(function));
387 }
388 template<class C, typename F, class FC>
389 void LuaInterface::bindClassMemberFunction(const std::string& className, const std::string& functionName, F FC::*function) {
390  registerClassMemberFunction(className, functionName, luabinder::bind_mem_fun<C>(function));
391 }
392 
393 template<class C, typename F1, typename F2, class FC>
394 void LuaInterface::bindClassMemberField(const std::string& fieldName, F1 FC::*getFunction, F2 FC::*setFunction) {
395  registerClassMemberField<C>(fieldName, luabinder::bind_mem_fun<C>(getFunction), luabinder::bind_mem_fun<C>(setFunction));
396 }
397 template<class C, typename F1, typename F2, class FC>
398 void LuaInterface::bindClassMemberField(const std::string& className, const std::string& fieldName, F1 FC::*getFunction, F2 FC::*setFunction) {
399  registerClassMemberField(className, fieldName, luabinder::bind_mem_fun<C>(getFunction), luabinder::bind_mem_fun<C>(setFunction));
400 }
401 
402 template<class C, typename F, class FC>
403 void LuaInterface::bindClassMemberGetField(const std::string& fieldName, F FC::*getFunction) {
404  registerClassMemberField<C>(fieldName, luabinder::bind_mem_fun<C>(getFunction), LuaCppFunction());
405 }
406 template<class C, typename F, class FC>
407 void LuaInterface::bindClassMemberGetField(const std::string& className, const std::string& fieldName, F FC::*getFunction) {
408  registerClassMemberField(className, fieldName, luabinder::bind_mem_fun<C>(getFunction), LuaCppFunction());
409 }
410 
411 template<class C, typename F, class FC>
412 void LuaInterface::bindClassMemberSetField(const std::string& fieldName, F FC::*setFunction) {
413  registerClassMemberField<C>(fieldName, LuaCppFunction(), luabinder::bind_mem_fun<C>(setFunction));
414 }
415 template<class C, typename F, class FC>
416 void LuaInterface::bindClassMemberSetField(const std::string& className, const std::string& fieldName, F FC::*setFunction) {
417  registerClassMemberField(className, fieldName, LuaCppFunction(), luabinder::bind_mem_fun<C>(setFunction));
418 }
419 
420 template<typename F>
421 void LuaInterface::bindGlobalFunction(const std::string& functionName, const F& function) {
422  registerGlobalFunction(functionName, luabinder::bind_fun(function));
423 }
424 
425 template<class T>
427  T o;
428  if(!luavalue_cast(index, o))
429  throw LuaBadValueCastException(typeName(index), stdext::demangle_type<T>());
430  return o;
431 }
432 
433 template<typename... T>
434 int LuaInterface::luaCallGlobalField(const std::string& global, const std::string& field, const T&... args) {
435  g_lua.getGlobalField(global, field);
436  if(!g_lua.isNil()) {
437  int numArgs = g_lua.polymorphicPush(args...);
438  return g_lua.signalCall(numArgs);
439  } else
440  g_lua.pop(1);
441  return 0;
442 }
443 
444 template<typename... T>
445 void LuaInterface::callGlobalField(const std::string& global, const std::string& field, const T&... args) {
446  int rets = luaCallGlobalField(global, field, args...);
447  if(rets > 0)
448  pop(rets);
449 }
450 
451 template<typename R, typename... T>
452 R LuaInterface::callGlobalField(const std::string& global, const std::string& field, const T&... args) {
453  R result;
454  int rets = luaCallGlobalField(global, field, args...);
455  if(rets > 0) {
456  assert(rets == 1);
457  result = g_lua.polymorphicPop<R>();
458  } else
459  result = R();
460  return result;
461 }
462 
463 #endif
LuaInterface::getField
void getField(const std::string &key, int index=-1)
Definition: luainterface.h:256
push_luavalue
int push_luavalue(const Outfit &outfit)
Definition: luavaluecasts.cpp:26
LuaInterface::insert
void insert(int index)
Definition: luainterface.cpp:819
LuaInterface::rawSeti
void rawSeti(int n, int index=-2)
Definition: luainterface.cpp:978
LuaInterface::useValue
void useValue()
Definition: luainterface.h:233
LuaCppFunction
std::function< int(LuaInterface *)> LuaCppFunction
Definition: declarations.h:31
LuaInterface::newUserdata
void * newUserdata(int size)
Definition: luainterface.cpp:994
LuaInterface::setGlobal
void setGlobal(const std::string &key)
Definition: luainterface.cpp:954
LuaInterface::isString
bool isString(int index=-1)
Definition: luainterface.cpp:1168
LuaInterface::isLuaFunction
bool isLuaFunction(int index=-1)
Definition: luainterface.h:309
LuaInterface::stackSize
int stackSize()
Definition: luainterface.h:321
LuaInterface::bindClassStaticFunction
void bindClassStaticFunction(const std::string &functionName, const F &function)
Definition: luainterface.h:376
LuaInterface::toString
std::string toString(int index=-1)
Definition: luainterface.cpp:1222
luaexception.h
luabinder::bind_singleton_mem_fun
LuaCppFunction bind_singleton_mem_fun(Ret(FC::*f)(Args...), C *instance)
Bind singleton member functions.
Definition: luabinder.h:195
LuaInterface::ref
int ref()
Definition: luainterface.cpp:756
LuaInterface::getTop
int getTop()
Definition: luainterface.cpp:1250
LuaInterface::call
void call(int numArgs=0, int numRets=0)
Definition: luainterface.cpp:744
LuaInterface::isNumber
bool isNumber(int index=-1)
Definition: luainterface.cpp:1162
LuaInterface::registerClassMemberFunction
void registerClassMemberFunction(const std::string &className, const std::string &functionName, const LuaCppFunction &function)
Definition: luainterface.cpp:157
LuaInterface::toObject
LuaObjectPtr toObject(int index=-1)
Definition: luainterface.cpp:1239
luavaluecasts.h
LuaInterface::callGlobalField
void callGlobalField(const std::string &global, const std::string &field, const T &... args)
Definition: luainterface.h:445
luavalue_cast
bool luavalue_cast(int index, Outfit &outfit)
Definition: luavaluecasts.cpp:52
LuaInterface::isCFunction
bool isCFunction(int index=-1)
Definition: luainterface.cpp:1186
LuaInterface::popObject
LuaObjectPtr popObject()
Definition: luainterface.cpp:1047
LuaInterface::popUpvalueUserdata
void * popUpvalueUserdata()
Definition: luainterface.cpp:1055
LuaInterface::checkStack
void checkStack()
Definition: luainterface.h:242
LuaInterface::closeLuaState
void closeLuaState()
Definition: luainterface.cpp:705
LuaInterface::registerSingletonClass
void registerSingletonClass(const std::string &className)
Definition: luainterface.cpp:79
LuaInterface::getGlobal
void getGlobal(const std::string &key)
Definition: luainterface.cpp:939
LuaInterface::init
void init()
Definition: luainterface.cpp:46
LuaInterface::setGlobalEnvironment
void setGlobalEnvironment(int env)
Definition: luainterface.cpp:859
LuaInterface::isFunction
bool isFunction(int index=-1)
Definition: luainterface.cpp:1180
LuaInterface::loadScript
void loadScript(const std::string &fileName)
Definition: luainterface.cpp:324
LuaInterface::hasIndex
bool hasIndex(int index)
Definition: luainterface.h:323
LuaInterface::traceback
std::string traceback(const std::string &errorMessage="", int level=0)
Definition: luainterface.cpp:380
LuaInterface::throwError
void throwError(const std::string &message)
Definition: luainterface.cpp:396
LuaInterface::clearTable
void clearTable(int index=-1)
Definition: luainterface.cpp:918
LuaInterface::registerClassMemberField
void registerClassMemberField(const std::string &field, const LuaCppFunction &getFunction, const LuaCppFunction &setFunction)
Definition: luainterface.h:81
LuaInterface::getField
void getField(const char *key, int index=-1)
Definition: luainterface.cpp:880
LuaInterface::bindClassMemberSetField
void bindClassMemberSetField(const std::string &fieldName, F FC::*setFunction)
Definition: luainterface.h:412
LuaInterface::getTable
void getTable(int index=-2)
Definition: luainterface.cpp:906
LuaInterface::polymorphicPush
int polymorphicPush(const T &v, const Args &... args)
Pushes any type onto the stack.
Definition: luainterface.h:358
LuaInterface::safeRunScript
bool safeRunScript(const std::string &fileName)
Loads and runs a script, any errors are printed to stdout and returns false.
Definition: luainterface.cpp:301
LuaInterface::pushNumber
void pushNumber(double v)
Definition: luainterface.cpp:1072
LuaInterface::toUserdata
void * toUserdata(int index=-1)
Definition: luainterface.cpp:1233
LuaInterface::createTable
void createTable(int narr, int nrec)
Definition: luainterface.cpp:989
LuaInterface::popString
std::string popString()
Definition: luainterface.cpp:1031
LuaInterface::bindClassMemberFunction
void bindClassMemberFunction(const std::string &functionName, F FC::*function)
Definition: luainterface.h:385
declarations.h
LuaInterface::bindClassMemberField
void bindClassMemberField(const std::string &fieldName, F1 FC::*getFunction, F2 FC::*setFunction)
Definition: luainterface.h:394
LuaInterface::weakRef
int weakRef()
Definition: luainterface.cpp:764
LuaInterface::isNil
bool isNil(int index=-1)
Definition: luainterface.cpp:1150
LuaInterface::popInteger
long popInteger()
Definition: luainterface.cpp:1007
LuaInterface::newSandboxEnv
int newSandboxEnv()
Creates a new environment table The new environment table is redirected to the global environment (ak...
Definition: luainterface.cpp:536
LuaInterface::setEnv
void setEnv(int index=-2)
Definition: luainterface.cpp:900
LuaInterface::rawGeti
void rawGeti(int n, int index=-1)
Definition: luainterface.cpp:966
LuaInterface::getEnv
void getEnv(int index=-1)
Definition: luainterface.cpp:894
LuaInterface::unref
void unref(int ref)
Definition: luainterface.cpp:786
LuaInterface::runBuffer
void runBuffer(const std::string &buffer, const std::string &source)
Definition: luainterface.cpp:318
LuaInterface::typeName
const char * typeName(int index=-1)
Definition: luainterface.cpp:792
LuaInterface::createLuaState
void createLuaState()
Definition: luainterface.cpp:664
LuaInterface::polymorphicPop
T polymorphicPop()
Same as castValue but also pops.
Definition: luainterface.h:339
LuaInterface::getMetatable
void getMetatable(int index=-1)
Definition: luainterface.cpp:874
LuaInterface::pushCString
void pushCString(const char *v)
Definition: luainterface.cpp:1084
LuaInterface::pushObject
void pushObject(const LuaObjectPtr &obj)
Definition: luainterface.cpp:1109
LuaCFunction
int(* LuaCFunction)(lua_State *L)
Definition: luainterface.h:29
LuaInterface::registerClassStaticFunction
void registerClassStaticFunction(const std::string &functionName, const LuaCppFunction &function)
Definition: luainterface.h:71
LuaInterface::getGlobalField
void getGlobalField(const std::string &globalKey, const std::string &fieldKey)
Definition: luainterface.cpp:944
LuaInterface::polymorphicPush
int polymorphicPush()
Definition: luainterface.h:330
LuaInterface::setMetatable
void setMetatable(int index=-2)
Definition: luainterface.cpp:868
LuaInterface
Class that manages LUA stuff.
Definition: luainterface.h:32
LuaInterface::loadBuffer
void loadBuffer(const std::string &buffer, const std::string &source)
Definition: luainterface.cpp:730
LuaInterface::pushString
void pushString(const std::string &v)
Definition: luainterface.cpp:1091
LuaInterface::pushValue
void pushValue(int index=-1)
Definition: luainterface.cpp:1143
g_lua
LuaInterface g_lua
Definition: luainterface.cpp:31
LuaInterface::popNumber
double popNumber()
Definition: luainterface.cpp:1015
LuaInterface::bindGlobalFunction
void bindGlobalFunction(const std::string &functionName, const F &function)
Definition: luainterface.h:421
LuaInterface::getCurrentSourcePath
std::string getCurrentSourcePath(int level=0)
Searches for the source of the current running function.
Definition: luainterface.cpp:405
LuaInterface::registerClassStaticFunction
void registerClassStaticFunction(const std::string &className, const std::string &functionName, const LuaCppFunction &function)
Definition: luainterface.cpp:150
LuaInterface::registerClass
void registerClass()
Definition: luainterface.h:66
LuaInterface::castValue
T castValue(int index=-1)
Definition: luainterface.h:426
LuaInterface::functionSourcePath
std::string functionSourcePath()
Definition: luainterface.cpp:799
LuaInterface::setField
void setField(const std::string &key, int index=-2)
Definition: luainterface.h:258
LuaInterface::pushCppFunction
void pushCppFunction(const LuaCppFunction &func)
Definition: luainterface.cpp:1127
LuaInterface::toCString
const char * toCString(int index=-1)
Definition: luainterface.cpp:1216
LuaInterface::terminate
void terminate()
Definition: luainterface.cpp:71
LuaInterface::resetGlobalEnvironment
void resetGlobalEnvironment()
Definition: luainterface.h:250
LuaInterface::signalCall
int signalCall(int numArgs=0, int numRets=-1)
Definition: luainterface.cpp:468
LuaInterface::isTable
bool isTable(int index=-1)
Definition: luainterface.cpp:1174
LuaInterface::registerClassMemberFunction
void registerClassMemberFunction(const std::string &functionName, const LuaCppFunction &function)
Definition: luainterface.h:76
LuaInterface::loadFiles
void loadFiles(std::string directory, bool recursive=false, std::string contains="")
Definition: luainterface.cpp:1255
LuaInterface::pop
void pop(int n=1)
Definition: luainterface.cpp:999
luabinder::bind_fun
LuaCppFunction bind_fun(const std::function< int(LuaInterface *)> &f)
Bind a customized function.
Definition: luabinder.h:110
stdext::shared_object_ptr
Definition: shared_object.h:39
LuaInterface::setField
void setField(const char *key, int index=-2)
Definition: luainterface.cpp:887
LuaBadValueCastException
Definition: luaexception.h:50
LuaInterface::isUserdata
bool isUserdata(int index=-1)
Definition: luainterface.cpp:1192
LuaInterface::registerGlobalFunction
void registerGlobalFunction(const std::string &functionName, const LuaCppFunction &function)
Definition: luainterface.cpp:187
LuaInterface::luaCallGlobalField
int luaCallGlobalField(const std::string &global, const std::string &field, const T &... args)
Definition: luainterface.h:434
LuaInterface::pushThread
void pushThread()
Definition: luainterface.cpp:1103
LuaInterface::runScript
void runScript(const std::string &fileName)
Definition: luainterface.cpp:312
LuaInterface::pcall
int pcall(int numArgs=0, int numRets=0, int errorFuncIndex=0)
Definition: luainterface.cpp:738
LuaInterface::getGlobalEnvironment
int getGlobalEnvironment()
Definition: luainterface.h:248
LuaInterface::isInCppCallback
bool isInCppCallback()
Definition: luainterface.h:200
LuaInterface::clearStack
void clearStack()
Definition: luainterface.h:322
LuaInterface::setTable
void setTable(int index=-3)
Definition: luainterface.cpp:912
LuaInterface::popBoolean
bool popBoolean()
Definition: luainterface.cpp:1023
LuaInterface::getWeakRef
void getWeakRef(int weakRef)
Definition: luainterface.cpp:851
LuaInterface::pushCFunction
void pushCFunction(LuaCFunction func, int n=0)
Definition: luainterface.cpp:1121
LuaInterface::LuaInterface
LuaInterface()
Definition: luainterface.cpp:33
LuaInterface::loadFunction
void loadFunction(const std::string &buffer, const std::string &source="lua function buffer")
Definition: luainterface.cpp:338
LuaInterface::pushLightUserdata
void pushLightUserdata(void *p)
Definition: luainterface.cpp:1097
LuaInterface::bindSingletonFunction
void bindSingletonFunction(const std::string &functionName, F C::*function, C *instance)
Definition: luainterface.h:366
LuaInterface::registerFunctions
void registerFunctions()
Register core script functions.
LuaInterface::pushInteger
void pushInteger(long v)
Definition: luainterface.cpp:1066
LuaInterface::error
void error()
Definition: luainterface.cpp:750
LuaInterface::collectGarbage
void collectGarbage()
Definition: luainterface.cpp:714
LuaInterface::toBoolean
bool toBoolean(int index=-1)
Definition: luainterface.cpp:1198
LuaInterface::getStackFunction
void getStackFunction(int level=0)
Definition: luainterface.cpp:837
LuaInterface::pushNil
void pushNil()
Definition: luainterface.cpp:1060
LuaInterface::getRef
void getRef(int ref)
Definition: luainterface.cpp:846
LuaInterface::remove
void remove(int index)
Definition: luainterface.cpp:825
LuaInterface::isBoolean
bool isBoolean(int index=-1)
Definition: luainterface.cpp:1156
luabinder.h
LuaInterface::bindClassMemberGetField
void bindClassMemberGetField(const std::string &fieldName, F FC::*getFunction)
Definition: luainterface.h:403
LuaInterface::rawSet
void rawSet(int index=-3)
Definition: luainterface.cpp:972
LuaInterface::toInteger
int toInteger(int index=-1)
Definition: luainterface.cpp:1204
LuaInterface::popUserdata
void * popUserdata()
Definition: luainterface.cpp:1039
LuaInterface::next
bool next(int index=-2)
Definition: luainterface.cpp:831
LuaInterface::~LuaInterface
~LuaInterface()
Definition: luainterface.cpp:42
LuaInterface::evaluateExpression
void evaluateExpression(const std::string &expression, const std::string &source="lua expression")
Definition: luainterface.cpp:362
LuaInterface::safeCall
int safeCall(int numArgs=0, int numRets=-1)
Calls a function The function and arguments must be on top of the stack in order, results are pushed ...
Definition: luainterface.cpp:432
LuaInterface::pushBoolean
void pushBoolean(bool v)
Definition: luainterface.cpp:1078
LuaInterface::registerClassMemberField
void registerClassMemberField(const std::string &className, const std::string &field, const LuaCppFunction &getFunction, const LuaCppFunction &setFunction)
Definition: luainterface.cpp:167
LuaInterface::rawGet
void rawGet(int index=-1)
Definition: luainterface.cpp:960
LuaInterface::toNumber
double toNumber(int index=-1)
Definition: luainterface.cpp:1210
LuaInterface::newTable
void newTable()
Definition: luainterface.cpp:984