aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/time/je_lua_timer.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-13 08:27:26 +0800
committerchai <chaifix@163.com>2018-11-13 08:27:26 +0800
commit75792c15480d3d99b2ba7e79e143e4b569b22611 (patch)
tree61e3abc45326c67d348e08400da11f60dff18fa3 /src/lua/modules/time/je_lua_timer.cpp
parentc7e59fb376453e5abad8c862b52eb0f4c7ba829b (diff)
*修改lua ref
Diffstat (limited to 'src/lua/modules/time/je_lua_timer.cpp')
-rw-r--r--src/lua/modules/time/je_lua_timer.cpp57
1 files changed, 24 insertions, 33 deletions
diff --git a/src/lua/modules/time/je_lua_timer.cpp b/src/lua/modules/time/je_lua_timer.cpp
index 42d4215..6e5c390 100644
--- a/src/lua/modules/time/je_lua_timer.cpp
+++ b/src/lua/modules/time/je_lua_timer.cpp
@@ -1,5 +1,5 @@
#include "../types.h"
-#include "lua/common/je_lua_function.h"
+#include "lua/common/je_lua_callback.h"
#include "lua/common/je_lua_common.h"
#include "je_lua_timer.h"
@@ -12,31 +12,15 @@ namespace JinEngine
typedef Shared<Timer>& SharedTimer;
- class Callback
- {
- public:
- Callback()
- {
- }
- ~Callback()
- {
- delete func;
- delete param;
- }
-
- LuaRef* func;
- LuaRef* param;
- };
-
- static Timer::TimerCallback Timer_Callback = [](void* data)->void
+ static Timer::TimerCallback timerCallback = [](void* data)->void
{
- LuaFunc* func = static_cast<LuaFunc*>(data);
+ LuaCallback* func = static_cast<LuaCallback*>(data);
func->call();
};
- static Timer::FinishCallback Finish_Callback = [](void* data)->void
+ static Timer::FinishCallback finishCallback = [](void* data)->void
{
- LuaFunc* func = static_cast<LuaFunc*>(data);
+ LuaCallback* func = static_cast<LuaCallback*>(data);
delete func;
};
@@ -49,13 +33,15 @@ namespace JinEngine
// timer:every(time, callback, parameter)
LUA_IMPLEMENT int l_every(lua_State* L)
{
+ int n = luax_gettop(L);
SharedTimer shared = checkTimer(L);
Timer* timer = shared.getObject();
float s = luax_checknumber(L, 2);
- LuaFunc* func = new LuaFunc(L);
- func->setFunc(3, 0);
- func->pushParam(4);
- Timer::Handler* handler = timer->every(s, Timer_Callback, func, Finish_Callback);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(3);
+ for(int i = 4; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->every(s, timerCallback, func, finishCallback);
Proxy* proxy = luax_newinstance(L, JIN_TIME_HANDLER);
proxy->bind(new Shared<Timer::Handler>(handler, JIN_TIME_HANDLER));
return 1;
@@ -64,13 +50,15 @@ namespace JinEngine
// timer:after(time, callback, parameter)
LUA_IMPLEMENT int l_after(lua_State* L)
{
+ int n = luax_gettop(L);
SharedTimer shared = checkTimer(L);
Timer* timer = shared.getObject();
float s = luax_checknumber(L, 2);
- LuaFunc* func = new LuaFunc(L);
- func->setFunc(3, 0);
- func->pushParam(4);
- Timer::Handler* handler = timer->after(s, Timer_Callback, func, Finish_Callback);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(3);
+ for (int i = 4; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->after(s, timerCallback, func, finishCallback);
Proxy* proxy = luax_newinstance(L, JIN_TIME_HANDLER);
proxy->bind(new Shared<Timer::Handler>(handler, JIN_TIME_HANDLER));
return 1;
@@ -79,14 +67,16 @@ namespace JinEngine
// timer:repeat(time, callback, parameter)
LUA_IMPLEMENT int l_repeat(lua_State* L)
{
+ int n = luax_gettop(L);
SharedTimer shared = checkTimer(L);
Timer* timer = shared.getObject();
float s = luax_checknumber(L, 2);
int count = luax_checkinteger(L, 3);
- LuaFunc* func = new LuaFunc(L);
- func->setFunc(4, 0);
- func->pushParam(5);
- Timer::Handler* handler = timer->repeat(s, count, Timer_Callback, func, Finish_Callback);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(4);
+ for (int i = 5; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->repeat(s, count, timerCallback, func, finishCallback);
Proxy* proxy = luax_newinstance(L, JIN_TIME_HANDLER);
proxy->bind(new Shared<Timer::Handler>(handler, JIN_TIME_HANDLER));
return 1;
@@ -140,6 +130,7 @@ namespace JinEngine
};
luax_newtype(L, JIN_TIME_TIMER, f);
+
return 0;
}