From 8cf0298ead2e6d2930fd528ea0fc901d83208ddf Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sun, 5 Jun 2016 18:08:58 +0000 Subject: MirLua: - GetContactInfo changed params place - reworked MT initialization git-svn-id: http://svn.miranda-ng.org/main/trunk@16921 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/mlua_utils.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'plugins/MirLua/src/mlua_utils.cpp') diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp index e4ea3efd11..26bcf22657 100644 --- a/plugins/MirLua/src/mlua_utils.cpp +++ b/plugins/MirLua/src/mlua_utils.cpp @@ -249,7 +249,7 @@ bool luaM_toboolean(lua_State *L, int idx) /***********************************************/ -static int blob_create(lua_State *L) +static int blob_new(lua_State *L) { BYTE *data = (BYTE*)lua_touserdata(L, 1); size_t size = luaL_checkinteger(L, 2); @@ -263,6 +263,17 @@ static int blob_create(lua_State *L) return 1; } +static int blob_call(lua_State *L) +{ + int nargs = lua_gettop(L); + lua_pushcfunction(L, blob_new); + for (int i = 2; i <= nargs; i++) + lua_pushvalue(L, i); + luaM_pcall(L, nargs - 1, 1); + + return 1; +} + static int blob__index(lua_State *L) { BLOB *blob = (BLOB*)luaL_checkudata(L, 1, MT_BLOB); @@ -303,6 +314,7 @@ static int blob__gc(lua_State *L) static const struct luaL_Reg blobApi[] = { + { "__call", blob_call }, { "__index", blob__index }, { "__newindex", blob__newindex }, { "__len", blob__len }, @@ -313,10 +325,17 @@ static const struct luaL_Reg blobApi[] = int luaopen_m_utils(lua_State *L) { - lua_register(L, MT_BLOB, blob_create); luaL_newmetatable(L, MT_BLOB); luaL_setfuncs(L, blobApi, 0); lua_pop(L, 1); + lua_createtable(L, 0, 1); + lua_pushcfunction(L, blob_new); + lua_setfield(L, -2, "new"); + lua_pushvalue(L, -1); + lua_setglobal(L, MT_BLOB); + luaL_setmetatable(L, MT_BLOB); + lua_pop(L, 1); + return 0; } \ No newline at end of file -- cgit v1.2.3