From 8d525f2f68c3c079f2888fdc911f0b5d7cfc8557 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Tue, 17 May 2016 12:24:12 +0000 Subject: MirLua: attempt to fix MT field reading git-svn-id: http://svn.miranda-ng.org/main/trunk@16838 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_database.cpp | 2 +- plugins/MirLua/src/mlua_metatable.h | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'plugins') diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp index f81baf06b6..4accb8cff9 100644 --- a/plugins/MirLua/src/m_database.cpp +++ b/plugins/MirLua/src/m_database.cpp @@ -675,7 +675,7 @@ int MT::Index(lua_State *L, CONTACTINFO *ci) return 1; } -void MT::Free(lua_State *L, CONTACTINFO **ci) +void MT::Free(lua_State* /*L*/, CONTACTINFO **ci) { mir_free((*ci)); } diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h index 13c2d614e3..6e8ddc3cf5 100644 --- a/plugins/MirLua/src/mlua_metatable.h +++ b/plugins/MirLua/src/mlua_metatable.h @@ -20,27 +20,28 @@ private: }; size_t offset; + size_t size; int type; - int getType; + + int getterType; std::function lambda; public: - MTField(size_t offset, int type) - : offset(offset), type(type), getType(MTFG_OFFSET) { } + MTField(size_t offset, size_t size, int type) + : offset(offset), size(size), type(type), getterType(MTFG_OFFSET) { } MTField(std::function f, int type) - : lambda(f), type(type), getType(MTFG_LAMBDA) { } + : lambda(f), type(type), getterType(MTFG_LAMBDA) { } int GetType() const { return type; } template R GetValue(T *obj) const { - if (getType == MTFG_LAMBDA) return (R)lambda(obj); + if (getterType == MTFG_LAMBDA) return (R)lambda(obj); else { R res = NULL; - size_t size = sizeof(R); memcpy(&res, ((char*)obj) + offset, size); return res; } @@ -114,7 +115,7 @@ private: switch (field->GetType()) { case LUA_TBOOLEAN: - lua_pushboolean(L, field->GetValue(obj)); + lua_pushboolean(L, field->GetValue(obj)); break; case LUA_TINTEGER: lua_pushinteger(L, field->GetValue(obj)); @@ -166,11 +167,13 @@ public: } template - MT& Field(R T::*M, const char *name, int type) + MT& Field(R T::*M, const char *name, int type, size_t size = 0) { + if (size == 0) + size = sizeof(M); size_t offset = offsetof(T, *M); if (type != LUA_TNONE) - fields[name] = new MTField(offset, type); + fields[name] = new MTField(offset, size, type); return *this; } -- cgit v1.2.3