GemaLuaCoreLib
The GeMA Lua Core library
Loading...
Searching...
No Matches
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
32class GmLogCategory;
33
35class GML_API_EXPORT GmLuaObject: public LuaProxy::Base
36{
37public:
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
48protected:
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
71private:
72 Q_DISABLE_COPY(GmLuaObject);
73
74 int gc (lua_State* L);
75 int tostring(lua_State* L);
76};
77
78#endif
A proxy class to export object methods to the Lua environment.
Definition gmLuaObject.h:36
const GmLogCategory & _logger
A logger used by the proxy when needed.
Definition gmLuaObject.h:62
virtual QString toString() const
Default method used by the __tostring metamethod to capture the result of tostring() over an object.
Definition gmLuaObject.h:55
virtual void fillMetatable(lua_State *L, int index)=0
Function called by populateMetatable() to fill the metatable with exported methods by derived classes...
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
QAtomicInteger< int > _refCount
Lua objects are reference counted to enable sharing them among different states. This is needed to al...
Definition gmLuaObject.h:69
virtual const char * typeName() const =0
Returns the object type as will be stored in the object metatable.
virtual void populateMetatable(lua_State *L, int index)=0
Declaration of the function used to prepare an environment with the core Lua functions.
void setValue(const T &value)