diff options
author | pixel <pixel> | 2008-05-14 01:39:31 +0000 |
---|---|---|
committer | pixel <pixel> | 2008-05-14 01:39:31 +0000 |
commit | a353ed440fd79c719ed325b6359a9f72a3ef6cea (patch) | |
tree | f7cf616f64e783f451b2f867527e4e24eec243ae /lib | |
parent | 8a1b1e91f6892cc51f7d18750a993c5fbcb321ca (diff) |
Adding the Delay task to Lua.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/LuaTask.cc | 22 | ||||
-rw-r--r-- | lib/tasklib.lua | 6 |
2 files changed, 23 insertions, 5 deletions
diff --git a/lib/LuaTask.cc b/lib/LuaTask.cc index 095c3e3..331e081 100644 --- a/lib/LuaTask.cc +++ b/lib/LuaTask.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: LuaTask.cc,v 1.28 2008-02-18 09:55:08 pixel Exp $ */ +/* $Id: LuaTask.cc,v 1.29 2008-05-14 01:39:31 pixel Exp $ */ #include <LuaTask.h> #include <LuaHandle.h> @@ -146,6 +146,10 @@ int LuaTask::Do() throw (GeneralException) { if (task == "Yield") { nargs = 0; } + + if (task == "Delay") { + nargs = 0; + } if (c) delete c; @@ -164,7 +168,6 @@ int LuaTask::Do() throw (GeneralException) { return TASK_DONE; #ifndef LUATASK_OMIT_HTTPCLIENT } else if (task == "HttpClient") { - String url = L->tostring(2); t_headers headers; Variables vars; @@ -194,10 +197,13 @@ int LuaTask::Do() throw (GeneralException) { L->pop(); } } + + if (L->gettop() <= 1) { + L->error("Incorrect number of parameters to HttpClient."); + } + String url = L->tostring(2); b = new Buffer(true); - - //headers.push_back("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) Gecko/20061010 Firefox/2.0"); c = new HttpClient(url, b, "", headers, vars); WaitFor(c); Suspend(TASK_ON_HOLD); @@ -267,6 +273,14 @@ int LuaTask::Do() throw (GeneralException) { #endif } else if (task == "Yield") { Yield(); + return TASK_ON_HOLD; + } else if (task == "Delay") { + if (L->gettop() != 2) { + L->error("Incorrect number of parameters to Delay"); + } + timeval delay_tv = { L->tonumber(), 0 }; + WaitFor(delay_tv); + return TASK_ON_HOLD; } else { L->error("Unknow requested task: " + task); return TASK_DONE; diff --git a/lib/tasklib.lua b/lib/tasklib.lua index a209ef3..75ea94a 100644 --- a/lib/tasklib.lua +++ b/lib/tasklib.lua @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: tasklib.lua,v 1.8 2008-02-18 09:55:08 pixel Exp $ */ +/* $Id: tasklib.lua,v 1.9 2008-05-14 01:39:31 pixel Exp $ */ ]]-- @@ -89,3 +89,7 @@ end function TaskYield() return coroutine.yield("Yield") end + +function Delay(delay) + return coroutine.yield("Delay", delay) +end |