From 0080cd035eaa00062b5f0f494be1e8862d8548b7 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sun, 24 Apr 2016 13:13:31 +0000 Subject: MirLua: fixed CONTACTINFO metatable git-svn-id: http://svn.miranda-ng.org/main/trunk@16760 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_database.cpp | 17 ++++++++--------- plugins/MirLua/src/mlua_metatable.h | 5 ++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp index a493970bfc..f81baf06b6 100644 --- a/plugins/MirLua/src/m_database.cpp +++ b/plugins/MirLua/src/m_database.cpp @@ -577,20 +577,14 @@ void MT::Free(lua_State*, DBEVENTINFO **dbei) void MT::Init(lua_State *L, CONTACTINFO **ci) { - MCONTACT hContact = 0; - switch (lua_type(L, 1)) + if (!lua_isinteger(L, 1)) { - case LUA_TNUMBER: - hContact = lua_tointeger(L, 1); - break; - case LUA_TLIGHTUSERDATA: - hContact = (MCONTACT)lua_touserdata(L, 1); - break; - default: const char *msg = lua_pushfstring(L, "hContact expected, got %s", luaL_typename(L, 1)); luaL_argerror(L, 1, msg); } + MCONTACT hContact = luaL_checkinteger(L, 1); + (*ci) = (CONTACTINFO*)mir_calloc(sizeof(CONTACTINFO)); (*ci)->cbSize = sizeof(CONTACTINFO); (*ci)->hContact = hContact; } @@ -681,6 +675,11 @@ int MT::Index(lua_State *L, CONTACTINFO *ci) return 1; } +void MT::Free(lua_State *L, CONTACTINFO **ci) +{ + mir_free((*ci)); +} + /***********************************************/ LUAMOD_API int luaopen_m_database(lua_State *L) diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h index 0946eb9caa..13c2d614e3 100644 --- a/plugins/MirLua/src/mlua_metatable.h +++ b/plugins/MirLua/src/mlua_metatable.h @@ -106,8 +106,7 @@ private: auto it = fields.find(key); if (it == fields.end()) { - lua_pushnil(L); - return 1; + return Index(L, obj); } MTField *field = it->second; @@ -136,7 +135,7 @@ private: lua_pushlightuserdata(L, field->GetValue(obj)); break; default: - return Index(L, obj); + lua_pushnil(L); } return 1; -- cgit v1.2.3