From 2c7da3b79ebbd1833d1edfdef52d14c2ef2547eb Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Wed, 17 Feb 2016 11:31:59 +0000 Subject: 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 --- plugins/MirLua/src/mlua_metatable.h | 38 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'plugins/MirLua/src/mlua_metatable.h') 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 -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 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 f, int type) - : lambda(f), type(type), getType(MTFGT_LAMBDA) { } + : lambda(f), type(type), getType(MTFG_LAMBDA) { } + + int GetType() const { return type; } template 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 *field = it->second; - switch (field->type) + switch (field->GetType()) { case LUA_TBOOLEAN: lua_pushboolean(L, field->GetValue(obj)); @@ -147,16 +151,16 @@ public: } template - 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(offset, size, type); + fields[name] = new MTField(offset, type); return *this; } - template - MT& Field(std::function f, const char *name, int type) + template + MT& Field(L &f, const char *name, int type) { if (type != LUA_TNONE) fields[name] = new MTField(f, type); -- cgit v1.2.3