From: Christian Heinrich Date: Thu, 23 Jul 2015 17:02:09 +0000 (+0200) Subject: [Lua] Ported console code to Lua 5.3 X-Git-Tag: v3_13~1644^2~17 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/40c77301656e053a13faf000cdf33f2a98677fb3 [Lua] Ported console code to Lua 5.3 --- diff --git a/examples/lua/console/master.lua b/examples/lua/console/master.lua index 36f9785360..379a79a326 100644 --- a/examples/lua/console/master.lua +++ b/examples/lua/console/master.lua @@ -5,28 +5,28 @@ -- under the terms of the license (GNU LGPL) which comes with this package. --Master Function -function Master(...) +function Master(...) - if #arg ~= 4 then - error("Wrong number of arguments (got " .. #arg .. - ", expected 4: nb_tasks comp_size comm_size slave_count)") + if select("#", ...) ~= 4 then + error("Wrong number of arguments (got " .. select("#", ...) .. + ", expected 4: nb_tasks comp_size comm_size slave_count)") end simgrid.info("Hello from lua, I'm the master") - for i,v in ipairs(arg) do + for i,v in ipairs({...}) do simgrid.info("Got " .. v) end - local nb_task, comp_size, comm_size, slave_count = unpack(arg) + local nb_task, comp_size, comm_size, slave_count = select(1, ...) - simgrid.info("Argc=" .. (#arg) .. " (should be 4)") + simgrid.info("Argc=" .. select("#", ...) .. " (should be 4)") -- Dispatch the tasks for i = 1, nb_task do task = simgrid.task.new("Task " .. i, comp_size, comm_size); local task_name = simgrid.task.get_name(task) - alias = "slave " .. (i%slave_count); + alias = "slave " .. string.format("%d",i%slave_count); simgrid.info("Master sending '" .. task_name .. "' To '" .. alias .. "'"); simgrid.task.send(task, alias); -- C user data set to NULL simgrid.info("Master done sending '" .. task_name .. "' To '" .. alias .. "'"); diff --git a/examples/lua/console/slave.lua b/examples/lua/console/slave.lua index b70a75a104..89f541982e 100644 --- a/examples/lua/console/slave.lua +++ b/examples/lua/console/slave.lua @@ -7,11 +7,11 @@ -- Slave Function --------------------------------------------------------- function Slave(...) - if #arg ~= 1 then + if select("#", ...) ~= 1 then error("Wrong number of arguments (got " .. #arg .. ", expected 1: slave_id)") end - local my_mailbox = "slave " .. arg[1] + local my_mailbox = "slave " .. select(1, ...) simgrid.info("Hello from lua, I'm a poor slave with mbox: " .. my_mailbox) while true do @@ -23,7 +23,7 @@ function Slave(...) simgrid.info("Slave '" .. my_mailbox .. "' got finalize msg"); break end - --local tk_name = simgrid.task.get_name(tk) + --local tk_name = simgrid.task.get_name(tk) simgrid.info("Slave '" .. my_mailbox .. "' processing " .. task:get_name()) simgrid.task.execute(task) simgrid.info("Slave '" .. my_mailbox .. "': task " .. task:get_name() .. " done") @@ -31,5 +31,5 @@ function Slave(...) simgrid.info("Slave '" .. my_mailbox .. "': I'm Done . See You !!"); -end +end -- end_of_slave