diff options
author | aunsane <aunsane@gmail.com> | 2018-08-02 22:06:15 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-08-02 22:06:15 +0300 |
commit | e15c30299953b10b1f5faa5d69cf6b56de4a0b61 (patch) | |
tree | d27bad909078ef0b32c3d0753a1de45776a05512 /plugins/MirLua/src/Modules | |
parent | 6d6b04fd4eaf40a4c6a4e2dfa9f0365afb12a2f3 (diff) |
MirLua: WaitOnHandle for m_core
Diffstat (limited to 'plugins/MirLua/src/Modules')
-rw-r--r-- | plugins/MirLua/src/Modules/m_core.cpp | 32 |
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 }, |