aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/time/je_lua_timer.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-12 21:58:05 +0800
committerchai <chaifix@163.com>2018-11-12 21:58:05 +0800
commitaf62f267a24091a16cbafe844d59cdbd4e78f5b1 (patch)
tree3862cee497b30a9c54761c7cd60c5de5af4a78d3 /src/lua/modules/time/je_lua_timer.cpp
parent72e45f0062d727cedd576d1e1251f6722454a119 (diff)
*使用int做状态机key
Diffstat (limited to 'src/lua/modules/time/je_lua_timer.cpp')
-rw-r--r--src/lua/modules/time/je_lua_timer.cpp51
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;