summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/mlua_metatable.h
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2016-02-17 11:31:59 +0000
committerAlexander Lantsev <aunsane@gmail.com>2016-02-17 11:31:59 +0000
commit2c7da3b79ebbd1833d1edfdef52d14c2ef2547eb (patch)
tree15beb4e894b43b7e0a9d5912e01dbdc0fd663d0e /plugins/MirLua/src/mlua_metatable.h
parentdf1277bc854e0db5424623890be9a3d74750a03f (diff)
MirLua:
- minor MT fixes - enabled chat module - project cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@16289 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/mlua_metatable.h')
-rw-r--r--plugins/MirLua/src/mlua_metatable.h38
1 files changed, 21 insertions, 17 deletions
diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h
index bef297905e..143c3a6ace 100644
--- a/plugins/MirLua/src/mlua_metatable.h
+++ b/plugins/MirLua/src/mlua_metatable.h
@@ -9,34 +9,38 @@
#define LUA_TSTRINGA LUA_NUMTAGS + 2
#define LUA_TSTRINGW LUA_NUMTAGS + 3
-enum MTFieldGetType
-{
- MTFGT_LAMBDA = 1,
- MTFGT_OFFSET = 2
-};
-
template<typename T>
-struct MTField : public MZeroedObject
+class MTField : public MZeroedObject
{
+private:
+ enum MTFieldGetter
+ {
+ MTFG_LAMBDA = 1,
+ MTFG_OFFSET = 2
+ };
+
size_t offset;
- size_t size;
int type;
int getType;
std::function<void*(T*)> lambda;
- MTField(size_t offset, size_t size, int type)
- : offset(offset), size(size), type(type), getType(MTFGT_OFFSET) { }
+public:
+ MTField(size_t offset, int type)
+ : offset(offset), type(type), getType(MTFG_OFFSET) { }
MTField(std::function<void*(T*)> f, int type)
- : lambda(f), type(type), getType(MTFGT_LAMBDA) { }
+ : lambda(f), type(type), getType(MTFG_LAMBDA) { }
+
+ int GetType() const { return type; }
template<typename R>
R GetValue(T *obj) const
{
- if (getType == MTFGT_LAMBDA) return (R)lambda(obj);
+ if (getType == MTFG_LAMBDA) return (R)lambda(obj);
else
{
R res = NULL;
+ size_t size = sizeof(R);
memcpy(&res, ((char*)obj) + offset, size);
return res;
}
@@ -93,7 +97,7 @@ private:
MTField<T> *field = it->second;
- switch (field->type)
+ switch (field->GetType())
{
case LUA_TBOOLEAN:
lua_pushboolean(L, field->GetValue<BOOL>(obj));
@@ -147,16 +151,16 @@ public:
}
template<typename R>
- MT& Field(R T::*M, const char *name, int type, size_t size = sizeof(R))
+ MT& Field(R T::*M, const char *name, int type)
{
size_t offset = offsetof(T, *M);
if (type != LUA_TNONE)
- fields[name] = new MTField<T>(offset, size, type);
+ fields[name] = new MTField<T>(offset, type);
return *this;
}
- template<typename R>
- MT& Field(std::function<R(T*)> f, const char *name, int type)
+ template<typename L>
+ MT& Field(L &f, const char *name, int type)
{
if (type != LUA_TNONE)
fields[name] = new MTField<T>(f, type);