From 784972ebca53b8141424e151c407f1fd004aeb3b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christophe=20Thi=C3=A9ry?= Date: Wed, 9 Nov 2011 20:15:42 +0100 Subject: [PATCH] Lua: merge simgrid.task.recv and simgrid.task.recv_with_timeout The timeout is now an optional argument of simgrid.task.recv. --- examples/lua/SimSplay/sim_splay.lua | 2 +- src/bindings/lua/simgrid_lua.c | 32 +++++++++++------------------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/examples/lua/SimSplay/sim_splay.lua b/examples/lua/SimSplay/sim_splay.lua index 41e42a8eb7..6202cb382c 100644 --- a/examples/lua/SimSplay/sim_splay.lua +++ b/examples/lua/SimSplay/sim_splay.lua @@ -75,7 +75,7 @@ end -- event Methods function events.sleep(time) my_mailbox = job.me.ip()..":"..job.me.port() - task = simgrid.task.recv_timeout(my_mailbox, time) + task = simgrid.task.recv(my_mailbox, time) if task ~= nil then -- an RPC call just woke me up diff --git a/src/bindings/lua/simgrid_lua.c b/src/bindings/lua/simgrid_lua.c index d29e6d56f4..a9aa62f42a 100644 --- a/src/bindings/lua/simgrid_lua.c +++ b/src/bindings/lua/simgrid_lua.c @@ -222,21 +222,29 @@ static int l_task_send(lua_State* L) } /** - * \brief Receives a task or fails after a timeout. + * \brief Receives a task. * \param L a Lua state * \return number of values returned to Lua * * - Argument 1 (string): mailbox - * - Argument 2 (number): timeout + * - Argument 2 (number, optional): timeout (default is no timeout) * - Return value (task/nil): the task received or nil if the communication * has failed */ -static int l_task_recv_with_timeout(lua_State *L) +static int l_task_recv(lua_State *L) { m_task_t task = NULL; const char* mailbox = luaL_checkstring(L, 1); - int timeout = luaL_checknumber(L, 2); + int timeout; + if (lua_gettop(L) >= 2) { /* mailbox timeout */ + timeout = luaL_checknumber(L, 2); + } + else { + /* mailbox */ + timeout = -1; + /* no timeout by default */ + } lua_settop(L, 0); /* -- */ MSG_error_t res = MSG_task_receive_with_timeout(&task, mailbox, timeout); @@ -270,21 +278,6 @@ static int l_task_recv_with_timeout(lua_State *L) return 1; } -/** - * \brief Receives a task. - * \param L a Lua state - * \return number of values returned to Lua - * - * - Argument 1 (string): mailbox - * - Return value (task/nil): the task received or nil if the communication - * has failed - */ -static int l_task_recv(lua_State * L) -{ - lua_pushnumber(L, -1.0); - return l_task_recv_with_timeout(L); -} - static const luaL_reg task_functions[] = { {"new", l_task_new}, {"name", l_task_get_name}, @@ -292,7 +285,6 @@ static const luaL_reg task_functions[] = { {"execute", l_task_execute}, {"send", l_task_send}, {"recv", l_task_recv}, - {"recv_timeout", l_task_recv_with_timeout}, {NULL, NULL} }; -- 2.20.1