summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-07-12 20:40:10 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-07-12 20:40:10 +0000
commitf1f08af4d7a1b4bedf55fb25af974276e5eb858c (patch)
tree70387cab585ac782ae7da679d95991f7403b3e39 /plugins
parent4bf1f71a53fb90e8c87f0e0a19af6e82b280867a (diff)
MirLua:
- Utf8Decode? functions are returns strings (thx to Mironych) - added DecodeCustomButtonClickData to m_msg_buttonsbar - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@14546 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/MirLua/src/m_core.cpp23
-rw-r--r--plugins/MirLua/src/m_message.cpp8
-rw-r--r--plugins/MirLua/src/m_msg_buttonsbar.cpp22
-rw-r--r--plugins/MirLua/src/mlua.cpp4
-rw-r--r--plugins/MirLua/src/mlua_module_loader.cpp2
-rw-r--r--plugins/MirLua/src/mlua_utils.cpp32
-rw-r--r--plugins/MirLua/src/stdafx.h3
-rw-r--r--plugins/MirLua/src/version.h2
8 files changed, 74 insertions, 22 deletions
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp
index 2a5564a07b..7fcbe1c2f5 100644
--- a/plugins/MirLua/src/m_core.cpp
+++ b/plugins/MirLua/src/m_core.cpp
@@ -162,30 +162,21 @@ static int lua_CallService(lua_State *L)
static int lua_Utf8DecodeA(lua_State *L)
{
- const char *string = luaL_checkstring(L, 1);
-
- char *res = mir_utf8decodeA(string);
- lua_pushlightuserdata(L, res);
-
- return 1;
+ return luaM_toansi(L);
}
static int lua_Utf8DecodeW(lua_State *L)
{
- const char *string = luaL_checkstring(L, 1);
-
- wchar_t *res = mir_utf8decodeW(string);
- lua_pushlightuserdata(L, res);
-
- return 1;
+ return luaM_toucs2(L);
}
static int lua_Free(lua_State *L)
{
- luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
- void *ptr = lua_touserdata(L, 1);
-
- mir_free(ptr);
+ if (lua_type(L, 1) == LUA_TLIGHTUSERDATA)
+ {
+ void *ptr = lua_touserdata(L, 1);
+ mir_free(ptr);
+ }
return 0;
}
diff --git a/plugins/MirLua/src/m_message.cpp b/plugins/MirLua/src/m_message.cpp
index f788b93f19..87e8e1a353 100644
--- a/plugins/MirLua/src/m_message.cpp
+++ b/plugins/MirLua/src/m_message.cpp
@@ -2,11 +2,11 @@
static int lua_Paste(lua_State *L)
{
- MCONTACT hContect = luaL_checkinteger(L, 1);
+ MCONTACT hContact = luaL_checkinteger(L, 1);
ptrT text(mir_utf8decodeT(luaL_checkstring(L, 2)));
MessageWindowInputData mwid = { sizeof(MessageWindowInputData) };
- mwid.hContact = luaL_checkinteger(L, 1);
+ mwid.hContact = hContact;
mwid.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH;
MessageWindowData mwd = { sizeof(MessageWindowData) };
@@ -26,11 +26,11 @@ static int lua_Paste(lua_State *L)
static int lua_Send(lua_State *L)
{
- MCONTACT hContect = luaL_checkinteger(L, 1);
+ MCONTACT hContact = luaL_checkinteger(L, 1);
ptrT text(mir_utf8decodeT(luaL_checkstring(L, 2)));
MessageWindowInputData mwid = { sizeof(MessageWindowInputData) };
- mwid.hContact = luaL_checkinteger(L, 1);
+ mwid.hContact = hContact;
mwid.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH;
MessageWindowData mwd = { sizeof(MessageWindowData) };
diff --git a/plugins/MirLua/src/m_msg_buttonsbar.cpp b/plugins/MirLua/src/m_msg_buttonsbar.cpp
index d150d81d79..9b3fc3b8e7 100644
--- a/plugins/MirLua/src/m_msg_buttonsbar.cpp
+++ b/plugins/MirLua/src/m_msg_buttonsbar.cpp
@@ -137,6 +137,27 @@ static int lua_OnMsgToolBarButtonPressed(lua_State *L)
return 1;
}
+static int lua_DecodeCustomButtonClickData(lua_State *L)
+{
+ CustomButtonClickData *bcd = (CustomButtonClickData*)lua_tointeger(L, 1);
+
+ lua_newtable(L);
+ lua_pushstring(L, "Module");
+ lua_pushstring(L, ptrA(mir_utf8encode(bcd->pszModule)));
+ lua_settable(L, -3);
+ lua_pushstring(L, "ButtonID");
+ lua_pushinteger(L, bcd->dwButtonId);
+ lua_settable(L, -3);
+ lua_pushstring(L, "hContact");
+ lua_pushinteger(L, bcd->hContact);
+ lua_settable(L, -3);
+ lua_pushstring(L, "Flags");
+ lua_pushinteger(L, bcd->flags);
+ lua_settable(L, -3);
+
+ return 1;
+}
+
static luaL_Reg msgbuttinsbarApi[] =
{
{ "AddButton", lua_AddButton },
@@ -144,6 +165,7 @@ static luaL_Reg msgbuttinsbarApi[] =
{ "RemoveButton", lua_RemoveButton },
{ "OnMsgToolBarButtonPressed", lua_OnMsgToolBarButtonPressed },
+ { "DecodeCustomButtonClickData", lua_DecodeCustomButtonClickData },
{ NULL, NULL }
};
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp
index 57fa08c7d5..6ce1b2d3f0 100644
--- a/plugins/MirLua/src/mlua.cpp
+++ b/plugins/MirLua/src/mlua.cpp
@@ -36,6 +36,10 @@ void CMLua::Load()
lua_getglobal(L, "_G");
lua_pushcclosure(L, luaM_print, 0);
lua_setfield(L, -2, "print");
+ lua_pushcclosure(L, luaM_toansi, 0);
+ lua_setfield(L, -2, "a");
+ lua_pushcclosure(L, luaM_toucs2, 0);
+ lua_setfield(L, -2, "u");
lua_pop(L, 1);
lua_atpanic(L, luaM_atpanic);
diff --git a/plugins/MirLua/src/mlua_module_loader.cpp b/plugins/MirLua/src/mlua_module_loader.cpp
index bc195cc701..391daadfa6 100644
--- a/plugins/MirLua/src/mlua_module_loader.cpp
+++ b/plugins/MirLua/src/mlua_module_loader.cpp
@@ -23,7 +23,7 @@ void CLuaModuleLoader::LoadModules()
PreloadModule(MLUA_GENMENU, luaopen_m_genmenu);
PreloadModule(MLUA_MESSAGE, luaopen_m_message);
PreloadModule(MLUA_MSGBUTTONSBAR, luaopen_m_msg_buttonsbar);
- PreloadModule(MLUA_POPUP, luaopen_m_popup);
+ PreloadModule(MLUA_POPUP, luaopen_m_popup);
PreloadModule(MLUA_TOPTOOLBAR, luaopen_m_toptoolbar);
PreloadModule(MLUA_VARIABLES, luaopen_m_variables);
PreloadModule(MLUA_WINDOWS, luaopen_m_windows);
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp
index 7fa59212c5..31af863da2 100644
--- a/plugins/MirLua/src/mlua_utils.cpp
+++ b/plugins/MirLua/src/mlua_utils.cpp
@@ -38,6 +38,32 @@ int luaM_atpanic(lua_State *L)
return 0;
}
+int luaM_toansi(lua_State *L)
+{
+ const char* value = luaL_checkstring(L, 1);
+ int codepage = luaL_optinteger(L, 2, Langpack_GetDefaultCodePage());
+
+ ptrA string(mir_strdup(value));
+ lua_pushstring(L, mir_utf8decodecp(string, codepage, NULL));
+
+ return 1;
+}
+
+int luaM_toucs2(lua_State *L)
+{
+ const char* value = luaL_checkstring(L, 1);
+
+ ptrW unicode(mir_utf8decodeW(value));
+ size_t length = mir_wstrlen(unicode) * sizeof(wchar_t);
+
+ ptrA string((char*)mir_calloc(length + 1));
+ memcpy(string, unicode, length);
+
+ lua_pushlstring(L, string, length + 1);
+
+ return 1;
+}
+
bool luaM_toboolean(lua_State *L, int idx)
{
if (lua_type(L, idx) == LUA_TNUMBER)
@@ -56,6 +82,9 @@ WPARAM luaM_towparam(lua_State *L, int idx)
case LUA_TNUMBER:
wParam = lua_tonumber(L, idx);
break;
+ case LUA_TSTRING:
+ wParam = (WPARAM)lua_tostring(L, idx);
+ break;
case LUA_TUSERDATA:
case LUA_TLIGHTUSERDATA:
wParam = (WPARAM)lua_touserdata(L, idx);
@@ -75,6 +104,9 @@ LPARAM luaM_tolparam(lua_State *L, int idx)
case LUA_TNUMBER:
lParam = lua_tonumber(L, idx);
break;
+ case LUA_TSTRING:
+ lParam = (LPARAM)lua_tostring(L, idx);
+ break;
case LUA_TUSERDATA:
case LUA_TLIGHTUSERDATA:
lParam = (LPARAM)lua_touserdata(L, idx);
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h
index d871d739ea..867d07f7e8 100644
--- a/plugins/MirLua/src/stdafx.h
+++ b/plugins/MirLua/src/stdafx.h
@@ -95,6 +95,9 @@ LUAMOD_API int (luaopen_m_windows)(lua_State *L);
int luaM_print(lua_State *L);
int luaM_atpanic(lua_State *L);
+int luaM_toansi(lua_State *L);
+int luaM_toucs2(lua_State *L);
+
bool luaM_toboolean(lua_State *L, int idx);
WPARAM luaM_towparam(lua_State *L, int idx);
LPARAM luaM_tolparam(lua_State *L, int idx);
diff --git a/plugins/MirLua/src/version.h b/plugins/MirLua/src/version.h
index 3a3afa1b3c..a3ff129847 100644
--- a/plugins/MirLua/src/version.h
+++ b/plugins/MirLua/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 3
-#define __BUILD_NUM 2
+#define __BUILD_NUM 3
#include <stdver.h>