summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/m_core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirLua/src/m_core.cpp')
-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 },