diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-06-21 20:38:33 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-06-21 20:38:33 +0000 |
commit | 932f5569c467683d3b95c45772da903d3117dc11 (patch) | |
tree | 73162154b5cbfc1b2826f58015dba8720732e9b5 | |
parent | 28e58637ba0b6194a2c95adf35f7581d5481a441 (diff) |
MirLua: some changes
git-svn-id: http://svn.miranda-ng.org/main/trunk@14311 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | plugins/MirLua/src/m_core.cpp | 8 | ||||
-rw-r--r-- | plugins/MirLua/src/m_toptoolbar.cpp | 8 | ||||
-rw-r--r-- | plugins/MirLua/src/main.cpp | 14 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 40 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.h | 3 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_utils.cpp | 43 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 2 |
7 files changed, 60 insertions, 58 deletions
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp index 72d899e5b9..917694e9e7 100644 --- a/plugins/MirLua/src/m_core.cpp +++ b/plugins/MirLua/src/m_core.cpp @@ -23,8 +23,8 @@ static int lua_DestroyHookableEvent(lua_State *L) static int lua_NotifyEventHooks(lua_State *L)
{
HANDLE hEvent = (HANDLE)lua_touserdata(L, 1);
- WPARAM wParam = CMLua::GetWParam(L, 2);
- LPARAM lParam = CMLua::GetLParam(L, 3);
+ WPARAM wParam = luaM_towparam(L, 2);
+ LPARAM lParam = luaM_tolparam(L, 3);
int res = ::NotifyEventHooks(hEvent, wParam, lParam);
lua_pushinteger(L, res);
@@ -156,8 +156,8 @@ static int lua_ServiceExists(lua_State *L) static int lua_CallService(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
- WPARAM wParam = CMLua::GetWParam(L, 2);
- LPARAM lParam = CMLua::GetLParam(L, 3);
+ WPARAM wParam = luaM_towparam(L, 2);
+ LPARAM lParam = luaM_tolparam(L, 3);
INT_PTR res = ::CallService(name, wParam, lParam);
lua_pushinteger(L, res);
diff --git a/plugins/MirLua/src/m_toptoolbar.cpp b/plugins/MirLua/src/m_toptoolbar.cpp index 7b0efcbc7c..535f919823 100644 --- a/plugins/MirLua/src/m_toptoolbar.cpp +++ b/plugins/MirLua/src/m_toptoolbar.cpp @@ -33,12 +33,12 @@ static TTBButton* MakeTBButton(lua_State *L) lua_pushstring(L, "wParamUp");
lua_gettable(L, -2);
- tbb->wParamUp = CMLua::GetWParam(L, -1);
+ tbb->wParamUp = luaM_towparam(L, -1);
lua_pop(L, 1);
lua_pushstring(L, "lParamUp");
lua_gettable(L, -2);
- tbb->lParamUp = CMLua::GetLParam(L, -1);
+ tbb->lParamUp = luaM_tolparam(L, -1);
lua_pop(L, 1);
// dn state
@@ -54,12 +54,12 @@ static TTBButton* MakeTBButton(lua_State *L) lua_pushstring(L, "wParamDown");
lua_gettable(L, -2);
- tbb->wParamDown = CMLua::GetWParam(L, -1);
+ tbb->wParamDown = luaM_towparam(L, -1);
lua_pop(L, 1);
lua_pushstring(L, "lParamDown");
lua_gettable(L, -2);
- tbb->lParamDown = CMLua::GetLParam(L, -1);
+ tbb->lParamDown = luaM_tolparam(L, -1);
lua_pop(L, 1);
return tbb;
diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp index b7062abd7f..a747a6ea9e 100644 --- a/plugins/MirLua/src/main.cpp +++ b/plugins/MirLua/src/main.cpp @@ -64,13 +64,13 @@ extern "C" int __declspec(dllexport) Load(void) if (db_get_b(NULL, MODULE, "ShowConsole", 0))
{
- if (AllocConsole())
- {
- freopen("CONOUT$", "wt", stdout);
- hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
- SetConsoleTitle(_T("MirLua Console"));
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
- }
+ if (!AttachConsole(ATTACH_PARENT_PROCESS))
+ if (AllocConsole())
+ {
+ freopen("CONOUT$", "w", stdout);
+ hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
+ SetConsoleTitle(_T("MirLua Console"));
+ }
}
g_hCommonFolderPath = FoldersRegisterCustomPathT("MirLua", Translate("Common scripts folder"), COMMON_SCRIPTS_PATHT);
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index f9772e0021..5e720dba8e 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -89,47 +89,7 @@ void CMLua::LoadScript(const char *path) printf("%s\n", lua_tostring(L, -1));
}
-WPARAM CMLua::GetWParam(lua_State *L, int idx)
-{
- WPARAM wParam = NULL;
- switch (lua_type(L, idx))
- {
- case LUA_TBOOLEAN:
- wParam = lua_toboolean(L, idx);
- break;
- case LUA_TNUMBER:
- wParam = lua_tonumber(L, idx);
- break;
- case LUA_TSTRING:
- wParam = (LPARAM)mir_utf8decode((char*)lua_tostring(L, idx), NULL);
- break;
- case LUA_TUSERDATA:
- wParam = (WPARAM)lua_touserdata(L, idx);
- break;
- }
- return wParam;
-}
-LPARAM CMLua::GetLParam(lua_State *L, int idx)
-{
- LPARAM lParam = NULL;
- switch (lua_type(L, idx))
- {
- case LUA_TBOOLEAN:
- lParam = lua_toboolean(L, idx);
- break;
- case LUA_TNUMBER:
- lParam = lua_tonumber(L, idx);
- break;
- case LUA_TSTRING:
- lParam = (LPARAM)mir_utf8decode((char*)lua_tostring(L, idx), NULL);
- break;
- case LUA_TUSERDATA:
- lParam = (LPARAM)lua_touserdata(L, idx);
- break;
- }
- return lParam;
-}
int CMLua::HookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param)
{
diff --git a/plugins/MirLua/src/mlua.h b/plugins/MirLua/src/mlua.h index fc10545c42..51d3a0b5bb 100644 --- a/plugins/MirLua/src/mlua.h +++ b/plugins/MirLua/src/mlua.h @@ -24,9 +24,6 @@ public: void AddScriptsPath(const char *path);
void LoadScript(const char *name);
- static WPARAM GetWParam(lua_State *L, int idx);
- static LPARAM GetLParam(lua_State *L, int idx);
-
static int HookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param);
};
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp new file mode 100644 index 0000000000..aab6823b85 --- /dev/null +++ b/plugins/MirLua/src/mlua_utils.cpp @@ -0,0 +1,43 @@ +#include "stdafx.h"
+
+WPARAM luaM_towparam(lua_State *L, int idx)
+{
+ WPARAM wParam = NULL;
+ switch (lua_type(L, idx))
+ {
+ case LUA_TBOOLEAN:
+ wParam = lua_toboolean(L, idx);
+ break;
+ case LUA_TNUMBER:
+ wParam = lua_tonumber(L, idx);
+ break;
+ case LUA_TSTRING:
+ wParam = (LPARAM)mir_utf8decode((char*)lua_tostring(L, idx), NULL);
+ break;
+ case LUA_TUSERDATA:
+ wParam = (WPARAM)lua_touserdata(L, idx);
+ break;
+ }
+ return wParam;
+}
+
+LPARAM luaM_tolparam(lua_State *L, int idx)
+{
+ LPARAM lParam = NULL;
+ switch (lua_type(L, idx))
+ {
+ case LUA_TBOOLEAN:
+ lParam = lua_toboolean(L, idx);
+ break;
+ case LUA_TNUMBER:
+ lParam = lua_tonumber(L, idx);
+ break;
+ case LUA_TSTRING:
+ lParam = (LPARAM)mir_utf8decode((char*)lua_tostring(L, idx), NULL);
+ break;
+ case LUA_TUSERDATA:
+ lParam = (LPARAM)lua_touserdata(L, idx);
+ break;
+ }
+ return lParam;
+}
\ No newline at end of file diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index b7bd486bac..9c8b26fd17 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -77,5 +77,7 @@ LUAMOD_API int (luaopen_m_toptoolbar)(lua_State *L); #define MLUA_VARIABLES "m_variables"
LUAMOD_API int (luaopen_m_variables)(lua_State *L);
+WPARAM luaM_towparam(lua_State *L, int idx);
+LPARAM luaM_tolparam(lua_State *L, int idx);
#endif //_COMMON_H_
|