summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/MirLua/src/m_core.cpp65
-rw-r--r--plugins/MirLua/src/m_protocols.cpp4
-rw-r--r--plugins/MirLua/src/mlua_utils.cpp81
-rw-r--r--plugins/MirLua/src/stdafx.h5
4 files changed, 45 insertions, 110 deletions
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp
index 3b7e841c1e..286365d9b0 100644
--- a/plugins/MirLua/src/m_core.cpp
+++ b/plugins/MirLua/src/m_core.cpp
@@ -114,8 +114,8 @@ static int core_NotifyEventHooks(lua_State *L)
{
luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
HANDLE hEvent = lua_touserdata(L, 1);
- WPARAM wParam = luaM_towparam(L, 2);
- LPARAM lParam = luaM_tolparam(L, 3);
+ WPARAM wParam = (WPARAM)luaM_tomparam(L, 2);
+ LPARAM lParam = (LPARAM)luaM_tomparam(L, 3);
int res = NotifyEventHooks(hEvent, wParam, lParam);
lua_pushboolean(L, res != -1);
@@ -201,8 +201,8 @@ static int core_CreateServiceFunction(lua_State *L)
static int core_CallService(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
- WPARAM wParam = luaM_towparam(L, 2);
- LPARAM lParam = luaM_tolparam(L, 3);
+ WPARAM wParam = (WPARAM)luaM_tomparam(L, 2);
+ LPARAM lParam = (LPARAM)luaM_tomparam(L, 3);
INT_PTR res = CallService(name, wParam, lParam);
lua_pushinteger(L, res);
@@ -284,7 +284,7 @@ static int core_Translate(lua_State *L)
return 1;
}
-static int core_ReplaceVariables(lua_State *L)
+static int core_Parse(lua_State *L)
{
char *what = (char*)luaL_checkstring(L, 1);
@@ -343,13 +343,16 @@ static int core_ForkThread(lua_State *L)
p->hThread = mir_forkthread(ThreadFunc, p);
lstThreads[p->hThread] = p;
- lua_pushnumber(L, (intptr_t)p->hThread);
+ lua_pushlightuserdata(L, p->hThread);
+
return 1;
}
static int core_TerminateThread(lua_State *L)
{
- HANDLE hThread = (HANDLE)(intptr_t)luaL_checknumber(L, 1);
+ luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+ HANDLE hThread = (HANDLE)lua_touserdata(L, 1);
+
auto it = lstThreads.find(hThread);
if (it != lstThreads.end())
{
@@ -357,6 +360,7 @@ static int core_TerminateThread(lua_State *L)
lua_pushboolean(L, TerminateThread(hThread, 0));
}
else lua_pushboolean(L, 0);
+
return 1;
}
@@ -372,7 +376,7 @@ int core_ptr2number(lua_State *L)
luaL_Reg coreApi[] =
{
{ "CreateHookableEvent", core_CreateHookableEvent },
- { "DestroyHookableEvent", core_DestroyHookableEvent },
+ //{ "DestroyHookableEvent", core_DestroyHookableEvent },
{ "NotifyEventHooks", core_NotifyEventHooks },
@@ -380,7 +384,7 @@ luaL_Reg coreApi[] =
{ "UnhookEvent", core_UnhookEvent },
{ "CreateServiceFunction", core_CreateServiceFunction },
- //{ "DestroyServiceFunction", core_DestroyServiceFunction },
+ { "DestroyServiceFunction", core_DestroyServiceFunction },
{ "ServiceExists", core_ServiceExists },
{ "CallService", core_CallService },
@@ -393,7 +397,9 @@ luaL_Reg coreApi[] =
{ "Free", core_Free },
{ "Translate", core_Translate },
- { "ReplaceVariables", core_ReplaceVariables },
+
+ { "Parse", core_Parse },
+ { "ReplaceVariables", core_Parse },
{ "ForkThread", core_ForkThread },
{ "TerminateThread", core_TerminateThread },
@@ -413,45 +419,6 @@ luaL_Reg coreApi[] =
/***********************************************/
-#define MT_WPARAM "WPARAM"
-#define MT_LPARAM "LPARAM"
-
-/*static int mp__call(lua_State *L)
-{
- switch (lua_type(L, idx))
- {
- case LUA_TBOOLEAN:
- return lua_toboolean(L, idx);
- case LUA_TNUMBER:
- return lua_tonumber(L, idx);
- case LUA_TSTRING:
- return (LPARAM)lua_tostring(L, idx);
- case LUA_TUSERDATA:
- case LUA_TLIGHTUSERDATA:
- return (LPARAM)lua_touserdata(L, idx);
- default:
- return NULL;
- }
-}
-
-static int mp__toboolean(lua_State *L)
-{
-}
-
-static int mp__tonumber(lua_State *L)
-{
-}
-
-static int mp__tostring(lua_State *L)
-{
-}
-
-static int mp__topointer(lua_State *L)
-{
-}*/
-
-/***********************************************/
-
LUAMOD_API int luaopen_m_core(lua_State *L)
{
luaL_newlib(L, coreApi);
diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp
index 5e30c1dad4..b7d861480f 100644
--- a/plugins/MirLua/src/m_protocols.cpp
+++ b/plugins/MirLua/src/m_protocols.cpp
@@ -61,8 +61,8 @@ static int lua_CallService(lua_State *L)
{
const char *module = luaL_checkstring(L, 1);
const char *service = luaL_checkstring(L, 2);
- WPARAM wParam = luaM_towparam(L, 3);
- LPARAM lParam = luaM_tolparam(L, 4);
+ WPARAM wParam = (WPARAM)luaM_tomparam(L, 3);
+ LPARAM lParam = (LPARAM)luaM_tomparam(L, 4);
INT_PTR res = CallProtoService(module, service, wParam, lParam);
lua_pushinteger(L, res);
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp
index d5ca5ed0bb..94e5e41434 100644
--- a/plugins/MirLua/src/mlua_utils.cpp
+++ b/plugins/MirLua/src/mlua_utils.cpp
@@ -165,6 +165,31 @@ int luaM_tonumber(lua_State *L)
return 1;
}
+UINT_PTR luaM_tomparam(lua_State *L, int idx)
+{
+ switch (lua_type(L, idx))
+ {
+ case LUA_TBOOLEAN:
+ return lua_toboolean(L, idx);
+ case LUA_TSTRING:
+ return (UINT_PTR)lua_tostring(L, idx);
+ case LUA_TLIGHTUSERDATA:
+ return (UINT_PTR)lua_touserdata(L, idx);
+ case LUA_TNUMBER:
+ {
+ if (lua_isinteger(L, 1))
+ {
+ lua_Integer value = lua_tointeger(L, 1);
+ return value <= INTPTR_MAX
+ ? (UINT_PTR)value
+ : NULL;
+ }
+ }
+ default:
+ return NULL;
+ }
+}
+
int luaM_interpolate(lua_State *L)
{
const char *string = luaL_checkstring(L, 1);
@@ -202,62 +227,6 @@ int luaM_interpolate(lua_State *L)
return 1;
}
-WPARAM luaM_towparam(lua_State *L, int idx)
-{
- if (lua_islightuserdata(L, idx))
- {
- return (WPARAM)lua_touserdata(L, idx);
- }
-
- char text[512];
- mir_snprintf(text, "Type %s is not supported. Use topointer(x) instead", luaL_typename(L, idx));
- Log(text);
- if (db_get_b(NULL, MODULE, "PopupOnObsolete", 0))
- ShowNotification(MODULE, text, MB_OK | MB_ICONWARNING, NULL);
-
- switch (lua_type(L, idx))
- {
- case LUA_TBOOLEAN:
- return lua_toboolean(L, idx);
- case LUA_TNUMBER:
- return (WPARAM)lua_tonumber(L, idx);
- case LUA_TSTRING:
- return (WPARAM)lua_tostring(L, idx);
- break;
- default:
- return NULL;
- }
-}
-
-LPARAM luaM_tolparam(lua_State *L, int idx)
-{
- if (lua_islightuserdata(L, idx))
- {
- return (LPARAM)lua_touserdata(L, idx);
- }
-
- char text[512];
- mir_snprintf(text, "Type %s is not supported. Use topointer(x) instead", luaL_typename(L, idx));
- Log(text);
- if (db_get_b(NULL, MODULE, "PopupOnObsolete", 0))
- ShowNotification(MODULE, text, MB_OK | MB_ICONWARNING, NULL);
-
- switch (lua_type(L, idx))
- {
- case LUA_TBOOLEAN:
- return lua_toboolean(L, idx);
- case LUA_TNUMBER:
- return (LPARAM)lua_tonumber(L, idx);
- case LUA_TSTRING:
- return (LPARAM)lua_tostring(L, idx);
- case LUA_TUSERDATA:
- case LUA_TLIGHTUSERDATA:
- return (LPARAM)lua_touserdata(L, idx);
- default:
- return NULL;
- }
-}
-
bool luaM_toboolean(lua_State *L, int idx)
{
if (lua_isnumber(L, idx))
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h
index 921d2c70c4..0bd6712d48 100644
--- a/plugins/MirLua/src/stdafx.h
+++ b/plugins/MirLua/src/stdafx.h
@@ -115,10 +115,9 @@ int luaM_toucs2(lua_State *L);
int luaM_topointer(lua_State *L);
int luaM_tonumber(lua_State *L);
-int luaM_interpolate(lua_State *L);
+WPARAM luaM_tomparam(lua_State *L, int idx);
-WPARAM luaM_towparam(lua_State *L, int idx);
-LPARAM luaM_tolparam(lua_State *L, int idx);
+int luaM_interpolate(lua_State *L);
bool luaM_toboolean(lua_State *L, int idx);