summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/Modules
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2018-08-02 22:06:15 +0300
committeraunsane <aunsane@gmail.com>2018-08-02 22:06:15 +0300
commite15c30299953b10b1f5faa5d69cf6b56de4a0b61 (patch)
treed27bad909078ef0b32c3d0753a1de45776a05512 /plugins/MirLua/src/Modules
parent6d6b04fd4eaf40a4c6a4e2dfa9f0365afb12a2f3 (diff)
MirLua: WaitOnHandle for m_core
Diffstat (limited to 'plugins/MirLua/src/Modules')
-rw-r--r--plugins/MirLua/src/Modules/m_core.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/plugins/MirLua/src/Modules/m_core.cpp b/plugins/MirLua/src/Modules/m_core.cpp
index 36cbcb3dc4..1a250ffccf 100644
--- a/plugins/MirLua/src/Modules/m_core.cpp
+++ b/plugins/MirLua/src/Modules/m_core.cpp
@@ -194,6 +194,36 @@ static int core_DestroyServiceFunction(lua_State *L)
/***********************************************/
+struct WainOnHandleParam
+{
+ lua_State *L;
+ int ref;
+};
+
+static void __stdcall OnWaitHandle(void *obj)
+{
+ WainOnHandleParam *param = (WainOnHandleParam*)obj;
+ lua_rawgeti(param->L, LUA_REGISTRYINDEX, param->ref);
+ luaM_pcall(param->L, 0, 0);
+ luaL_unref(param->L, LUA_REGISTRYINDEX, param->ref);
+ delete param;
+}
+
+static int core_WaitOnHandle(lua_State *L)
+{
+ luaL_checktype(L, 1, LUA_TFUNCTION);
+
+ lua_pushvalue(L, 1);
+ int ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+ WainOnHandleParam *param = new WainOnHandleParam { L, ref };
+ Miranda_WaitOnHandleEx(OnWaitHandle, param);
+
+ return 0;
+}
+
+/***********************************************/
+
static int core_IsPluginLoaded(lua_State *L)
{
const char *value = lua_tostring(L, 1);
@@ -328,6 +358,8 @@ luaL_Reg coreApi[] =
{ "ServiceExists", core_ServiceExists },
{ "CallService", core_CallService },
+ { "WaitOnHandle", core_WaitOnHandle },
+
{ "IsPluginLoaded", core_IsPluginLoaded },
{ "Free", core_Free },