Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[Lua] Ported console code to Lua 5.3
[simgrid.git] / examples / lua / console / slave.lua
1 -- Copyright (c) 2011, 2013-2014. The SimGrid Team.
2 -- All rights reserved.
3
4 -- This program is free software; you can redistribute it and/or modify it
5 -- under the terms of the license (GNU LGPL) which comes with this package.
6
7 -- Slave Function ---------------------------------------------------------
8 function Slave(...)
9
10   if select("#", ...) ~= 1 then
11     error("Wrong number of arguments (got " .. #arg .. ", expected 1: slave_id)")
12   end
13
14   local my_mailbox = "slave " .. select(1, ...)
15   simgrid.info("Hello from lua, I'm a poor slave with mbox: " .. my_mailbox)
16
17   while true do
18
19     local task = simgrid.task.recv(my_mailbox);
20     --print(task)
21     local task_name = task:get_name()
22     if (task:get_name() == "finalize") then
23       simgrid.info("Slave '" .. my_mailbox .. "' got finalize msg");
24       break
25     end
26     --local tk_name = simgrid.task.get_name(tk)
27     simgrid.info("Slave '" .. my_mailbox .. "' processing " .. task:get_name())
28     simgrid.task.execute(task)
29     simgrid.info("Slave '"  .. my_mailbox .. "': task " .. task:get_name() .. " done")
30   end -- while
31
32   simgrid.info("Slave '" .. my_mailbox .. "': I'm Done . See You !!");
33
34 end
35 -- end_of_slave