summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-01-24 08:23:04 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-01-24 08:23:04 +0000
commit4d1349db1c91c1cb9ca6e3e984081ab0b1195757 (patch)
tree158440065f1826ef00989ab1a125aae79b7b6b93
parent99862342bba952d2042b3b572ffb228a0b05cf1f (diff)
MirLua: ForkThread function
git-svn-id: http://svn.miranda-ng.org/main/trunk@16160 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/MirLua/src/m_core.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp
index 339a2e8419..ac58662508 100644
--- a/plugins/MirLua/src/m_core.cpp
+++ b/plugins/MirLua/src/m_core.cpp
@@ -255,6 +255,46 @@ static int core_GetFullPath(lua_State *L)
return 1;
}
+
+struct core_ForkThreadParam
+{
+ lua_State *L;
+ int threadRef;
+ int functionRef;
+};
+
+void __cdecl ThreadFunc(void *p)
+{
+ core_ForkThreadParam *ftp = (core_ForkThreadParam*)p;
+
+ lua_rawgeti(ftp->L, LUA_REGISTRYINDEX, ftp->functionRef);
+ luaM_pcall(ftp->L, 0, 1);
+
+ luaL_unref(ftp->L, LUA_REGISTRYINDEX, ftp->functionRef);
+ luaL_unref(ftp->L, LUA_REGISTRYINDEX, ftp->threadRef);
+ delete ftp;
+}
+
+static int core_ForkThread(lua_State *L)
+{
+ core_ForkThreadParam *p = new core_ForkThreadParam();
+ p->L = lua_newthread(L);
+ p->threadRef = luaL_ref(L, LUA_REGISTRYINDEX);
+ lua_pushvalue(L, 1);
+ p->functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
+ HANDLE hThread = mir_forkthread(ThreadFunc, p);
+ lua_pushnumber(L, (intptr_t)hThread);
+ return 1;
+}
+
+static int core_TerminateThread(lua_State *L)
+{
+ HANDLE hThread = (HANDLE)(intptr_t)luaL_checknumber(L, 1);
+ BOOL res = TerminateThread(hThread, 0);
+ lua_pushboolean(L, res);
+ return 1;
+}
+
luaL_Reg coreApi[] =
{
{ "CreateHookableEvent", core_CreateHookableEvent },
@@ -281,6 +321,9 @@ luaL_Reg coreApi[] =
{ "Translate", core_Translate },
{ "ReplaceVariables", core_ReplaceVariables },
+ { "ForkThread", core_ForkThread },
+ { "TerminateThread", core_TerminateThread },
+
{ "PointerToNumber", luaM_ptr2number },
{ "GetFullPath", core_GetFullPath },