summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/MirLua/src/m_chat.cpp1
-rw-r--r--plugins/MirLua/src/m_database.cpp17
-rw-r--r--plugins/MirLua/src/m_message.cpp1
-rw-r--r--plugins/MirLua/src/m_protocols.cpp4
-rw-r--r--plugins/MirLua/src/mlua_metatable.h30
-rw-r--r--plugins/MirLua/src/mlua_utils.cpp23
6 files changed, 53 insertions, 23 deletions
diff --git a/plugins/MirLua/src/m_chat.cpp b/plugins/MirLua/src/m_chat.cpp
index 7619fab7d6..da45fd93e4 100644
--- a/plugins/MirLua/src/m_chat.cpp
+++ b/plugins/MirLua/src/m_chat.cpp
@@ -20,7 +20,6 @@ LUAMOD_API int luaopen_m_chat(lua_State *L)
.Field(&GCEVENT::ptszUID, "Uid", LUA_TSTRINGW)
.Field(&GCEVENT::ptszStatus, "Status", LUA_TSTRINGW)
.Field(&GCEVENT::ptszText, "Text", LUA_TSTRINGW);
- lua_pop(L, 1);
return 1;
}
diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp
index b9482ed7f8..081ba1dd95 100644
--- a/plugins/MirLua/src/m_database.cpp
+++ b/plugins/MirLua/src/m_database.cpp
@@ -55,12 +55,14 @@ static int db_Contacts(lua_State *L)
static int db_GetContactInfo(lua_State *L)
{
+ MCONTACT hContact = luaL_checkinteger(L, 1);
+
int type = 0;
- if (lua_isnumber(L, 1))
- type = lua_tointeger(L, 1);
- else if (lua_isstring(L, 1))
+ if (lua_isnumber(L, 2))
+ type = lua_tointeger(L, 2);
+ else if (lua_isstring(L, 2))
{
- const char *key = luaL_checkstring(L, 1);
+ const char *key = luaL_checkstring(L, 2);
if (mir_strcmpi(key, "FirstName") == 0)
type = CNF_FIRSTNAME;
@@ -101,10 +103,7 @@ static int db_GetContactInfo(lua_State *L)
}
}
- MCONTACT hContact = luaL_checkinteger(L, 2);
- const char *proto = lua_tostring(L, 3);
-
- ptrT value(Contact_GetInfo(type, hContact, proto));
+ ptrT value(Contact_GetInfo(type, hContact));
if (value)
lua_pushstring(L, ptrA(mir_utf8encodeT(value)));
else
@@ -580,7 +579,6 @@ LUAMOD_API int luaopen_m_database(lua_State *L)
MT<DBCONTACTWRITESETTING>(L, MT_DBCONTACTWRITESETTING)
.Field(&DBCONTACTWRITESETTING::szModule, "Module", LUA_TSTRINGA)
.Field(&DBCONTACTWRITESETTING::szSetting, "Setting", LUA_TSTRINGA);
- lua_pop(L, 1);
MT<DBEVENTINFO>(L, MT_DBEVENTINFO)
.Field(&DBEVENTINFO::szModule, "Module", LUA_TSTRINGA)
@@ -589,7 +587,6 @@ LUAMOD_API int luaopen_m_database(lua_State *L)
.Field(&DBEVENTINFO::flags, "Flags", LUA_TINTEGER)
.Field(&DBEVENTINFO::cbBlob, "Length", LUA_TINTEGER)
.Field(&DBEVENTINFO::pBlob, "Blob", LUA_TLIGHTUSERDATA);
- lua_pop(L, 1);
return 1;
}
diff --git a/plugins/MirLua/src/m_message.cpp b/plugins/MirLua/src/m_message.cpp
index 6a84276afe..707489b24c 100644
--- a/plugins/MirLua/src/m_message.cpp
+++ b/plugins/MirLua/src/m_message.cpp
@@ -85,7 +85,6 @@ LUAMOD_API int luaopen_m_message(lua_State *L)
.Field(&MessageWindowEventData::uType, "Type", LUA_TINTEGER)
.Field(&MessageWindowEventData::hContact, "hContact", LUA_TINTEGER)
.Field(&MessageWindowEventData::uFlags, "Flags", LUA_TINTEGER);
- lua_pop(L, 1);
return 1;
}
diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp
index 9ea8f4b833..493978283c 100644
--- a/plugins/MirLua/src/m_protocols.cpp
+++ b/plugins/MirLua/src/m_protocols.cpp
@@ -160,7 +160,6 @@ LUAMOD_API int luaopen_m_protocols(lua_State *L)
MT<PROTOCOLDESCRIPTOR>(L, "PROTOCOLDESCRIPTOR")
.Field(&PROTOCOLDESCRIPTOR::szName, "Name", LUA_TSTRINGA)
.Field(&PROTOCOLDESCRIPTOR::type, "Type", LUA_TINTEGER);
- lua_pop(L, 1);
MT<PROTOACCOUNT>(L, "PROTOACCOUNT")
.Field(&PROTOACCOUNT::szModuleName, "ModuleName", LUA_TSTRINGA)
@@ -170,7 +169,6 @@ LUAMOD_API int luaopen_m_protocols(lua_State *L)
.Field(&PROTOACCOUNT::bIsVisible, "IsVisible", LUA_TBOOLEAN)
.Field(&PROTOACCOUNT::bIsVirtual, "IsVirtual", LUA_TBOOLEAN)
.Field(&PROTOACCOUNT::bOldProto, "IsOldProto", LUA_TBOOLEAN);
- lua_pop(L, 1);
MT<ACKDATA>(L, "ACKDATA")
.Field(&ACKDATA::szModule, "Module", LUA_TSTRINGA)
@@ -179,12 +177,10 @@ LUAMOD_API int luaopen_m_protocols(lua_State *L)
.Field(&ACKDATA::result, "Result", LUA_TINTEGER)
.Field(&ACKDATA::hProcess, "hProcess", LUA_TLIGHTUSERDATA)
.Field(&ACKDATA::lParam, "lParam", LUA_TLIGHTUSERDATA);
- lua_pop(L, 1);
MT<CCSDATA>(L, "CCSDATA")
.Field(&CCSDATA::hContact, "hContact", LUA_TINTEGER)
.Field([](CCSDATA *ccs) { return ((PROTORECVEVENT*)ccs->lParam)->szMessage; }, "Message", LUA_TSTRING);
- lua_pop(L, 1);
return 1;
}
diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h
index e67f54ee6d..fe1e2eba10 100644
--- a/plugins/MirLua/src/mlua_metatable.h
+++ b/plugins/MirLua/src/mlua_metatable.h
@@ -74,7 +74,7 @@ private:
*obj = NULL;
}
- static int lua_new(lua_State *L)
+ static int lua__new(lua_State *L)
{
T **udata = (T**)lua_newuserdata(L, sizeof(T*));
Init(L, udata);
@@ -90,6 +90,17 @@ private:
static int lua__call(lua_State *L)
{
+ int nargs = lua_gettop(L);
+ lua_pushcfunction(L, lua__new);
+ for (int i = 2; i <= nargs; i++)
+ lua_pushvalue(L, i);
+ luaM_pcall(L, nargs - 1, 1);
+
+ return 1;
+ }
+
+ static int lua__bnot(lua_State *L)
+ {
T *obj = *(T**)luaL_checkudata(L, 1, MT::name);
lua_pushlightuserdata(L, obj);
@@ -152,15 +163,24 @@ public:
{
MT::name = tname;
- lua_register(L, MT::name, lua_new);
-
luaL_newmetatable(L, MT::name);
- lua_pushcfunction(L, lua__index);
- lua_setfield(L, -2, "__index");
lua_pushcfunction(L, lua__call);
lua_setfield(L, -2, "__call");
+ lua_pushcfunction(L, lua__index);
+ lua_setfield(L, -2, "__index");
+ lua_pushcfunction(L, lua__bnot);
+ lua_setfield(L, -2, "__bnot");
lua_pushcfunction(L, lua__gc);
lua_setfield(L, -2, "__gc");
+ lua_pop(L, 1);
+
+ lua_createtable(L, 0, 1);
+ lua_pushcfunction(L, lua__new);
+ lua_setfield(L, -2, "new");
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, MT::name);
+ luaL_setmetatable(L, MT::name);
+ lua_pop(L, 1);
}
template<typename R>
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