Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[Lua] Ported masterslave code to Lua 5.3
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Thu, 23 Jul 2015 17:00:14 +0000 (19:00 +0200)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Thu, 15 Oct 2015 17:17:18 +0000 (19:17 +0200)
examples/lua/masterslave/master.lua
examples/lua/masterslave/slave.lua

index 0cd88bc..31ee9c5 100644 (file)
@@ -4,23 +4,23 @@
 -- This program is free software; you can redistribute it and/or modify it
 -- under the terms of the license (GNU LGPL) which comes with this package.
 
-function Master(...) 
+function Master(...)
 
-  if #arg ~= 4 then
+  if select("#", ...) ~= 4 then
     error("Wrong number of arguments (got " .. #arg ..
         ", expected 4: nb_tasks comp_size comm_size slave_count)")
   end
 
+  local nb_task, comp_size, comm_size, slave_count = select(1, ...)
   simgrid.info("Hello from lua, I'm the master")
 
-  local nb_task, comp_size, comm_size, slave_count = unpack(arg)
 
   -- Dispatch the tasks
 
   for i = 1, nb_task do
     local task = simgrid.task.new("Task " .. i, comp_size, comm_size)
     local task_name = task:get_name()
-    local alias = "slave " .. (i % slave_count)
+    local alias = "slave " .. string.format("%d", i % slave_count)
     simgrid.info("Sending  '" .. task_name .. "' to '" .. alias .."'")
     task:send(alias) -- C user data set to NULL
     simgrid.info("Done sending '".. task_name .. "' to '" .. alias .."'")
index d6f2141..e1ade87 100644 (file)
@@ -6,11 +6,11 @@
 
 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 mailbox: " .. my_mailbox)
 
   while true do