From e15c30299953b10b1f5faa5d69cf6b56de4a0b61 Mon Sep 17 00:00:00 2001 From: aunsane Date: Thu, 2 Aug 2018 22:06:15 +0300 Subject: MirLua: WaitOnHandle for m_core --- plugins/MirLua/src/Modules/m_core.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'plugins/MirLua/src/Modules') 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 }, -- cgit v1.2.3