From 69f7d1bd745ed5680b9bc4e3cfdd882ff2a5ad26 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 27 Mar 2019 22:18:14 +0800 Subject: +threading --- .../threading/binding/_coroutine.cpp | 40 ++++++++ .../asura-lib-utils/threading/binding/_thread.cpp | 104 +++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 source/libs/asura-lib-utils/threading/binding/_coroutine.cpp create mode 100644 source/libs/asura-lib-utils/threading/binding/_thread.cpp (limited to 'source/libs/asura-lib-utils/threading/binding') diff --git a/source/libs/asura-lib-utils/threading/binding/_coroutine.cpp b/source/libs/asura-lib-utils/threading/binding/_coroutine.cpp new file mode 100644 index 0000000..7f74cca --- /dev/null +++ b/source/libs/asura-lib-utils/threading/binding/_coroutine.cpp @@ -0,0 +1,40 @@ +#include "../coroutine.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Threading + { + + LUAX_REGISTRY(Coroutine) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "Run", _Run } + ); + } + + LUAX_POSTPROCESS(Coroutine) + { + + } + + // Coroutine.New() + LUAX_IMPL_METHOD(Coroutine, _New) + { + LUAX_STATE(L); + + return 0; + } + + // coroutine:Run() + LUAX_IMPL_METHOD(Coroutine, _Run) + { + LUAX_PREPARE(L, Coroutine); + + return 0; + } + + } +} diff --git a/source/libs/asura-lib-utils/threading/binding/_thread.cpp b/source/libs/asura-lib-utils/threading/binding/_thread.cpp new file mode 100644 index 0000000..9f6d228 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/binding/_thread.cpp @@ -0,0 +1,104 @@ +#include "../thread.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Threading + { + + LUAX_REGISTRY(Thread) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "Start", _Start }, + { "Join", _Join }, + { "Kill", _Kill }, + { "AddTask", _AddTask }, + { "IsRunning", _IsRunning }, + { "IsCurrent", _IsCurrent }, + { "GetName", _GetName } + ); + } + + LUAX_POSTPROCESS(Thread) + { + + } + + // thread = Thread.New(name) + LUAX_IMPL_METHOD(Thread, _New) + { + LUAX_STATE(L); + + cc8* name = state.GetValue(1, ""); + + Thread* thread = new Thread(name); + thread->PushLuaxUserdata(state); + + return 1; + } + + // thread:Start() + LUAX_IMPL_METHOD(Thread, _Start) + { + LUAX_PREPARE(L, Thread); + self->Start(); + return 0; + } + + // thread:Join() + LUAX_IMPL_METHOD(Thread, _Join) + { + LUAX_PREPARE(L, Thread); + self->Join(); + return 0; + } + + // thread:Kill() + LUAX_IMPL_METHOD(Thread, _Kill) + { + LUAX_PREPARE(L, Thread); + self->Kill(); + return 0; + } + + // successed = thread:AddTask(thread_task) + LUAX_IMPL_METHOD(Thread, _AddTask) + { + LUAX_PREPARE(L, Thread); + + ThreadTask* task = state.GetUserdata(2); + self->AddTask(task); + self->LuaxRetain(state, task); + return 0; + } + + // thread:IsRunning() + LUAX_IMPL_METHOD(Thread, _IsRunning) + { + LUAX_PREPARE(L, Thread); + + state.Push(self->IsRunning()); + return 0; + } + + // thread:IsCurrent() + LUAX_IMPL_METHOD(Thread, _IsCurrent) + { + LUAX_PREPARE(L, Thread); + + state.Push(self->IsCurrent()); + return 0; + } + + // thread:GetName() + LUAX_IMPL_METHOD(Thread, _GetName) + { + LUAX_PREPARE(L, Thread); + + return 0; + } + + } +} -- cgit v1.1-26-g67d0