diff options
Diffstat (limited to 'source/libs/asura-lib-utils/threading/binding/_thread.cpp')
-rw-r--r-- | source/libs/asura-lib-utils/threading/binding/_thread.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
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<cc8*>(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<ThreadTask>(2); + self->AddTask(task); + self->LuaxRetain<ThreadTask>(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; + } + + } +} |