diff options
Diffstat (limited to 'plugins/MirLua/src')
| -rw-r--r-- | plugins/MirLua/src/m_chat.cpp | 20 | ||||
| -rw-r--r-- | plugins/MirLua/src/m_database.cpp | 91 | ||||
| -rw-r--r-- | plugins/MirLua/src/m_message.cpp | 8 | ||||
| -rw-r--r-- | plugins/MirLua/src/m_msg_buttonsbar.cpp | 8 | ||||
| -rw-r--r-- | plugins/MirLua/src/m_protocols.cpp | 16 | 
5 files changed, 107 insertions, 36 deletions
diff --git a/plugins/MirLua/src/m_chat.cpp b/plugins/MirLua/src/m_chat.cpp index fb3b9d9ad9..57a37ae7bd 100644 --- a/plugins/MirLua/src/m_chat.cpp +++ b/plugins/MirLua/src/m_chat.cpp @@ -108,25 +108,25 @@ static int gce__index(lua_State *L)  	GCEVENT *gce = (GCEVENT*)luaL_checkudata(L, 1, MT_GCEVENT);
  	const char *key = luaL_checkstring(L, 2);
 -	if (mir_strcmpi(key, "Module"))
 +	if (mir_strcmpi(key, "Module") == 0)
  		lua_pushstring(L, gce->pDest->pszModule);
 -	if (mir_strcmpi(key, "Id"))
 +	else if (mir_strcmpi(key, "Id") == 0)
  		lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
 -	if (mir_strcmpi(key, "Type"))
 +	else if (mir_strcmpi(key, "Type") == 0)
  		lua_pushinteger(L, gce->pDest->iType);
 -	if (mir_strcmpi(key, "Timestamp"))
 +	else if (mir_strcmpi(key, "Timestamp") == 0)
  		lua_pushnumber(L, gce->time);
 -	if (mir_strcmpi(key, "IsMe"))
 +	else if (mir_strcmpi(key, "IsMe") == 0)
  		lua_pushboolean(L, gce->bIsMe);
 -	if (mir_strcmpi(key, "Flags"))
 +	else if (mir_strcmpi(key, "Flags") == 0)
  		lua_pushinteger(L, gce->dwFlags);
 -	if (mir_strcmpi(key, "Uid"))
 +	else if (mir_strcmpi(key, "Uid") == 0)
  		lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
 -	if (mir_strcmpi(key, "Nick"))
 +	else if (mir_strcmpi(key, "Nick") == 0)
  		lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
 -	if (mir_strcmpi(key, "Status"))
 +	else if (mir_strcmpi(key, "Status") == 0)
  		lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
 -	if (mir_strcmpi(key, "Text"))
 +	else if (mir_strcmpi(key, "Text") == 0)
  		lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID)));
  	else
  		lua_pushnil(L);
 diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp index 29191403e7..bd21d1ec26 100644 --- a/plugins/MirLua/src/m_database.cpp +++ b/plugins/MirLua/src/m_database.cpp @@ -23,18 +23,18 @@ static int lua_FindNextContact(lua_State *L)  static int lua_ContactIterator(lua_State *L)
  {
 -	MCONTACT hContact = lua_tointeger(L, lua_upvalueindex(1));
 -	const char *szProto = lua_tostring(L, lua_upvalueindex(2));
 +	const char *szProto = lua_tostring(L, lua_upvalueindex(1));
 +	MCONTACT hContact = lua_tointeger(L, lua_upvalueindex(2));
  	hContact = hContact == NULL
  		? db_find_first(szProto)
 -		: db_find_next(hContact);
 +		: db_find_next(hContact, szProto);
  	if (hContact)
  	{
  		lua_pushinteger(L, hContact);
  		lua_pushvalue(L, -1);
 -		lua_replace(L, lua_upvalueindex(1));
 +		lua_replace(L, lua_upvalueindex(2));
  	}
  	else
  		lua_pushnil(L);
 @@ -109,6 +109,8 @@ static int lua_GetLastEvent(lua_State *L)  static int lua_GetEvent(lua_State *L)
  {
 +	ObsoleteMethod(L, "Use totable(x, \"DBEVENTINFO\") instead");
 +
  	MEVENT hEvent = luaL_checkinteger(L, 1);
  	DBEVENTINFO dbei = { sizeof(DBEVENTINFO) };
 @@ -164,7 +166,7 @@ static int lua_EventIterator(lua_State *L)  	if (hEvent)
  	{
 -		lua_pushinteger(L, hContact);
 +		lua_pushinteger(L, hEvent);
  		lua_pushvalue(L, -1);
  		lua_replace(L, lua_upvalueindex(2));
  	}
 @@ -342,8 +344,8 @@ static int lua_SettingIterator(lua_State *L)  static int lua_AllSettings(lua_State *L)
  {
 -	MCONTACT hContact = lua_tointeger(L, 1);
 -	const char* szModule = luaL_checkstring(L, 2);
 +	const char* szModule = luaL_checkstring(L, 1);
 +	MCONTACT hContact = lua_tointeger(L, 2);
  	enumDBSettingsParam* param = (enumDBSettingsParam*)mir_alloc(sizeof(enumDBSettingsParam));
  	param->count = 0;
 @@ -581,6 +583,71 @@ static luaL_Reg databaseApi[] =  	{ NULL, NULL }
  };
 +#define MT_DBEVENTINFO "DBEVENTINFO"
 +
 +static int dbei__init(lua_State *L)
 +{
 +	MEVENT hEvent = lua_tointeger(L, 1);
 +
 +	DBEVENTINFO *dbei = (DBEVENTINFO*)lua_newuserdata(L, sizeof(DBEVENTINFO));
 +	dbei->cbSize = sizeof(DBEVENTINFO);
 +	dbei->cbBlob = db_event_getBlobSize(hEvent);
 +	dbei->pBlob = (PBYTE)mir_calloc(dbei->cbBlob);
 +	db_event_get(hEvent, dbei);
 +
 +	luaL_setmetatable(L, MT_DBEVENTINFO);
 +
 +	return 1;
 +}
 +
 +static int dbei__index(lua_State *L)
 +{
 +	DBEVENTINFO *dbei = (DBEVENTINFO*)luaL_checkudata(L, 1, MT_DBEVENTINFO);
 +	const char *key = luaL_checkstring(L, 2);
 +
 +	if (mir_strcmpi(key, "Module") == 0)
 +		lua_pushstring(L, ptrA(mir_utf8encode(dbei->szModule)));
 +	else if (mir_strcmpi(key, "Timestamp") == 0)
 +		lua_pushnumber(L, dbei->timestamp);
 +	else if (mir_strcmpi(key, "Type") == 0)
 +		lua_pushinteger(L, dbei->eventType);
 +	else if (mir_strcmpi(key, "Flags") == 0)
 +		lua_pushinteger(L, dbei->flags);
 +	else if (mir_strcmpi(key, "Length") == 0)
 +		lua_pushnumber(L, dbei->cbBlob);
 +	else if (mir_strcmpi(key, "Blob") == 0)
 +	{
 +		lua_newtable(L);
 +		for (DWORD i = 0; i < dbei->cbBlob; i++)
 +		{
 +			lua_pushinteger(L, i + 1);
 +			lua_pushinteger(L, dbei->pBlob[i]);
 +			lua_settable(L, -3);
 +		}
 +	}
 +	else
 +		lua_pushnil(L);
 +
 +	return 1;
 +}
 +
 +static int dbei__gc(lua_State *L)
 +{
 +	DBEVENTINFO *dbei = (DBEVENTINFO*)luaL_checkudata(L, 1, MT_DBEVENTINFO);
 +
 +	mir_free(dbei->pBlob);
 +
 +	return 1;
 +}
 +
 +static const luaL_Reg dbeiMeta[] =
 +{
 +	{ "__init", dbei__init },
 +	{ "__index", dbei__index },
 +	{ "__gc", dbei__gc },
 +	{ NULL, NULL }
 +};
 +
  #define MT_DBCONTACTWRITESETTING "DBCONTACTWRITESETTING"
  static int dbcw__init(lua_State *L)
 @@ -605,11 +672,11 @@ static int dbcw__index(lua_State *L)  	DBCONTACTWRITESETTING *dbcw = (DBCONTACTWRITESETTING*)luaL_checkudata(L, 1, MT_DBCONTACTWRITESETTING);
  	const char *key = luaL_checkstring(L, 2);
 -	if (mir_strcmpi(key, "Module"))
 +	if (mir_strcmpi(key, "Module") == 0)
  		lua_pushstring(L, dbcw->szModule);
 -	if (mir_strcmpi(key, "Setting"))
 +	else if (mir_strcmpi(key, "Setting") == 0)
  		lua_pushstring(L, dbcw->szSetting);
 -	if (mir_strcmpi(key, "Value"))
 +	else if (mir_strcmpi(key, "Value") == 0)
  	{
  		switch (dbcw->value.type)
  		{
 @@ -653,6 +720,10 @@ LUAMOD_API int luaopen_m_database(lua_State *L)  {
  	luaL_newlib(L, databaseApi);
 +	luaL_newmetatable(L, MT_DBEVENTINFO);
 +	luaL_setfuncs(L, dbeiMeta, 0);
 +	lua_pop(L, 1);
 +
  	luaL_newmetatable(L, MT_DBCONTACTWRITESETTING);
  	luaL_setfuncs(L, dbcwMeta, 0);
  	lua_pop(L, 1);
 diff --git a/plugins/MirLua/src/m_message.cpp b/plugins/MirLua/src/m_message.cpp index 1722671689..4855e18299 100644 --- a/plugins/MirLua/src/m_message.cpp +++ b/plugins/MirLua/src/m_message.cpp @@ -157,13 +157,13 @@ static int mwed__index(lua_State *L)  	MessageWindowEventData *mwed = *(MessageWindowEventData**)luaL_checkudata(L, 1, MT_MESSAGEWINDOWEVENTDATA);
  	const char *key = lua_tostring(L, 2);
 -	if (!mir_strcmpi(key, "Module"))
 +	if (!mir_strcmpi(key, "Module") == 0)
  		lua_pushstring(L, ptrA(mir_utf8encode(mwed->szModule)));
 -	if (!mir_strcmpi(key, "Type"))
 +	else if (!mir_strcmpi(key, "Type") == 0)
  		lua_pushinteger(L, mwed->uType);
 -	if (!mir_strcmpi(key, "hContact"))
 +	else if (!mir_strcmpi(key, "hContact") == 0)
  		lua_pushinteger(L, mwed->hContact);
 -	if (!mir_strcmpi(key, "Flags"))
 +	else if (!mir_strcmpi(key, "Flags") == 0)
  		lua_pushinteger(L, mwed->uFlags);
  	else
  		lua_pushnil(L);
 diff --git a/plugins/MirLua/src/m_msg_buttonsbar.cpp b/plugins/MirLua/src/m_msg_buttonsbar.cpp index b7824e78aa..a5007f7d46 100644 --- a/plugins/MirLua/src/m_msg_buttonsbar.cpp +++ b/plugins/MirLua/src/m_msg_buttonsbar.cpp @@ -236,13 +236,13 @@ static int bcd__index(lua_State *L)  	CustomButtonClickData *bcd = *(CustomButtonClickData**)luaL_checkudata(L, 1, MT_CUSTOMBUTTONCLICKDATA);
  	const char *key = lua_tostring(L, 2);
 -	if (!mir_strcmpi(key, "Module"))
 +	if (mir_strcmpi(key, "Module") == 0)
  		lua_pushstring(L, ptrA(mir_utf8encode(bcd->pszModule)));
 -	else if (!mir_strcmpi(key, "ButtonID"))
 +	else if (mir_strcmpi(key, "ButtonID") == 0)
  		lua_pushinteger(L, bcd->dwButtonId);
 -	else if (!mir_strcmpi(key, "hContact"))
 +	else if (mir_strcmpi(key, "hContact") == 0)
  		lua_pushinteger(L, bcd->hContact);
 -	else if (!mir_strcmpi(key, "Flags"))
 +	else if (mir_strcmpi(key, "Flags") == 0)
  		lua_pushinteger(L, bcd->flags);
  	else
  		lua_pushnil(L);
 diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp index 05be204deb..696b519cae 100644 --- a/plugins/MirLua/src/m_protocols.cpp +++ b/plugins/MirLua/src/m_protocols.cpp @@ -347,17 +347,17 @@ static int ack__index(lua_State *L)  	ACKDATA *ack = *(ACKDATA**)luaL_checkudata(L, 1, MT_ACKDATA);
  	const char *key = lua_tostring(L, 2);
 -	if (!mir_strcmpi(key, "Module"))
 +	if (mir_strcmpi(key, "Module") == 0)
  		lua_pushstring(L, ptrA(mir_utf8encode(ack->szModule)));
 -	if (!mir_strcmpi(key, "hContact"))
 +	else if (mir_strcmpi(key, "hContact") == 0)
  		lua_pushinteger(L, ack->hContact);
 -	if (!mir_strcmpi(key, "Type"))
 +	else if (mir_strcmpi(key, "Type") == 0)
  		lua_pushinteger(L, ack->type);
 -	if (!mir_strcmpi(key, "Result"))
 +	else if (mir_strcmpi(key, "Result") == 0)
  		lua_pushinteger(L, ack->result);
 -	if (!mir_strcmpi(key, "hProcess"))
 +	else if (mir_strcmpi(key, "hProcess") == 0)
  		lua_pushlightuserdata(L, ack->hProcess);
 -	if (!mir_strcmpi(key, "lParam"))
 +	else if (mir_strcmpi(key, "lParam") == 0)
  		lua_pushnumber(L, ack->lParam);
  	else
  		lua_pushnil(L);
 @@ -396,9 +396,9 @@ static int ccs__index(lua_State *L)  	CCSDATA *ccs = *(CCSDATA**)luaL_checkudata(L, 1, MT_CCSDATA);
  	const char *key = lua_tostring(L, 2);
 -	if (!mir_strcmpi(key, "hContact"))
 +	if (mir_strcmpi(key, "hContact") == 0)
  		lua_pushinteger(L, ccs->hContact);
 -	if (!mir_strcmpi(key, "Message"))
 +	else if (mir_strcmpi(key, "Message") == 0)
  	{
  		PROTORECVEVENT *pre = (PROTORECVEVENT*)ccs->lParam;
  		lua_pushstring(L, pre->szMessage);
  | 
