Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
26fe0e899dcb884a807c1bc4023373016a7d5da4
[simgrid.git] / examples / lua / state_cloner / duplicated_globals.lua
1 -- Copyright (c) 2011, 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 -- This code creates 3 simgrid processes and verifies that the global values
8 -- in each Lua world are correctly cloned from maestro and become different
9
10 require("simgrid")
11
12 global_string = "A global string set by maestro"
13
14 -- Assigns to the global string the first argument and prints it
15 function set_global_string(...)
16
17   global_string = select(1, ...)
18   simgrid.info("Changing the global string")
19   print_global()
20 end
21
22 -- Replaces the function please_dont_change_me() by set_global_string()
23 -- and calls it
24 function replace(...)
25
26   simgrid.info("Overwriting function please_dont_replace_me()")
27   please_dont_replace_me = set_global_string
28   please_dont_replace_me(...)
29 end
30
31 -- Shows a hello message and prints the global string
32 function please_dont_replace_me(...)
33
34   simgrid.info("Hello from please_dont_replace_me(). I'm lucky, I still exist in this state.")
35   print_global()
36 end
37
38 -- Prints the value of global_string
39 function print_global()
40
41   simgrid.info("Global string is '" .. global_string .. "'")
42 end
43
44 print_global()
45
46 simgrid.platform("../../platforms/small_platform.xml")
47 simgrid.application("deployment_duplicated_globals.xml")
48 simgrid.run()
49