diff options
Diffstat (limited to 'src/lua/modules/time/je_lua_timer.cpp')
-rw-r--r-- | src/lua/modules/time/je_lua_timer.cpp | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/src/lua/modules/time/je_lua_timer.cpp b/src/lua/modules/time/je_lua_timer.cpp index c79c16b..239d1dd 100644 --- a/src/lua/modules/time/je_lua_timer.cpp +++ b/src/lua/modules/time/je_lua_timer.cpp @@ -1,4 +1,5 @@ #include "../types.h" +#include "lua/common/je_lua_function.h" #include "lua/common/je_lua_common.h" #include "je_lua_timer.h" @@ -23,23 +24,21 @@ namespace JinEngine delete param; } - Reference* func; - Reference* param; + LuaRef* func; + LuaRef* param; }; -#define TIMER_CALLBACK \ -[=](void* data)->void { \ - Callback* cbk = static_cast<Callback*>(data); \ - cbk->func->push(); \ - cbk->param->push(); \ - luax_call(L, 1, 0); \ -} + static Timer::TimerCallback Timer_Callback = [](void* data)->void + { + LuaFunc* func = static_cast<LuaFunc*>(data); + func->call(); + }; -#define FINISH_CALLBACK \ -[=](void* data) { \ - Callback* cbk = static_cast<Callback*>(data); \ - delete cbk; \ -} + static Timer::FinishCallback Finish_Callback = [](void* data)->void + { + LuaFunc* func = static_cast<LuaFunc*>(data); + delete func; + }; LUA_IMPLEMENT inline SharedTimer checkTimer(lua_State* L) { @@ -53,10 +52,10 @@ namespace JinEngine SharedTimer shared = checkTimer(L); Timer* timer = shared.getObject(); float s = luax_checknumber(L, 2); - Callback* callback = new Callback(); - callback->func = new Reference(L, 3); - callback->param = new Reference(L, 4); - Timer::Handler* handler = timer->every(s, TIMER_CALLBACK, callback, FINISH_CALLBACK); + LuaFunc* func = new LuaFunc(L); + func->setFunc(3, 0); + func->pushParam(4); + Timer::Handler* handler = timer->every(s, Timer_Callback, func, Finish_Callback); Proxy* proxy = luax_newinstance(L, JIN_TIME_HANDLER); proxy->bind(new Shared<Timer::Handler>(handler, JIN_TIME_HANDLER)); return 1; @@ -68,10 +67,10 @@ namespace JinEngine SharedTimer shared = checkTimer(L); Timer* timer = shared.getObject(); float s = luax_checknumber(L, 2); - Callback* callback = new Callback(); - callback->func = new Reference(L, 3); - callback->param = new Reference(L, 4); - Timer::Handler* handler = timer->after(s, TIMER_CALLBACK, callback, FINISH_CALLBACK); + LuaFunc* func = new LuaFunc(L); + func->setFunc(3, 0); + func->pushParam(4); + Timer::Handler* handler = timer->after(s, Timer_Callback, func, Finish_Callback); Proxy* proxy = luax_newinstance(L, JIN_TIME_HANDLER); proxy->bind(new Shared<Timer::Handler>(handler, JIN_TIME_HANDLER)); return 1; @@ -84,10 +83,10 @@ namespace JinEngine Timer* timer = shared.getObject(); float s = luax_checknumber(L, 2); int count = luax_checkinteger(L, 3); - Callback* callback = new Callback(); - callback->func = new Reference(L, 4); - callback->param = new Reference(L, 5); - Timer::Handler* handler = timer->repeat(s, count, TIMER_CALLBACK, callback, FINISH_CALLBACK); + LuaFunc* func = new LuaFunc(L); + func->setFunc(4, 0); + func->pushParam(5); + Timer::Handler* handler = timer->repeat(s, count, Timer_Callback, func, Finish_Callback); Proxy* proxy = luax_newinstance(L, JIN_TIME_HANDLER); proxy->bind(new Shared<Timer::Handler>(handler, JIN_TIME_HANDLER)); return 1; |