GemaLuaCoreLib
The GeMA Lua Core library
gmLuaObject.h
Go to the documentation of this file.
1 /************************************************************************
2 **
3 ** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4 ** All rights reserved.
5 **
6 ** This file is part of the "GeMA" software. It's use should respect
7 ** the terms in the license agreement that can be found together
8 ** with this source code.
9 ** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10 ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11 ** A PARTICULAR PURPOSE.
12 **
13 ************************************************************************/
14 
24 #ifndef _GEMALUA_OBJECT_H_
25 #define _GEMALUA_OBJECT_H_
26 
27 #include "gmLuaEnv.h"
28 #include <luaProxy.h>
29 
30 #include <QAtomicInteger>
31 
32 class GmLogCategory;
33 
35 class GML_API_EXPORT GmLuaObject: public LuaProxy::Base
36 {
37 public:
38  virtual ~GmLuaObject();
39 
40  virtual void populateMetatable(lua_State* L, int index);
41 
43  QVariant ptrToVariant() { QVariant v; v.setValue<void*>(this); return v; }
44 
46  void ref() { _refCount.ref(); }
47 
48 protected:
49  GmLuaObject(const GmLogCategory& logger);
50 
52  virtual const char* typeName() const = 0;
53 
55  virtual QString toString() const { return typeName(); }
56 
60  virtual void fillMetatable(lua_State* L, int index) = 0;
61 
63 
70 
71 private:
72  Q_DISABLE_COPY(GmLuaObject);
73 
74  int gc (lua_State* L);
75  int tostring(lua_State* L);
76 };
77 
78 #endif
const GmLogCategory & _logger
A logger used by the proxy when needed.
Definition: gmLuaObject.h:62
QAtomicInteger< int > _refCount
Lua objects are reference counted to enable sharing them among different states. This is needed to al...
Definition: gmLuaObject.h:69
Declaration of the function used to prepare an environment with the core Lua functions.
void ref()
Increments the object reference count. Use with care.
Definition: gmLuaObject.h:46
QVariant ptrToVariant()
Constructs a QVariant storing a POINTER to the current object.
Definition: gmLuaObject.h:43
void setValue(const T &value)
virtual void populateMetatable(lua_State *L, int index)=0
virtual QString toString() const
Default method used by the __tostring metamethod to capture the result of tostring() over an object.
Definition: gmLuaObject.h:55
A proxy class to export object methods to the Lua environment.
Definition: gmLuaObject.h:35