Permalink
Browse files

Return a local table variable for the main module

The codebase has been modified in order for the main module and its
submodules to return local variables, so as not to pollute the global
environment.  Also, now the returned table, only contains the public API
methods, as the submodules and their methods can be accessed without
having them stored there.  The documentation, examples and tests have
been also updated to reflect this change.
  • Loading branch information...
lefcha committed Mar 27, 2012
1 parent 2559e08 commit c6951019830ffa9b62aede03962729bb01cc5502
Showing with 955 additions and 1,061 deletions.
  1. +36 −76 doc/manual.html
  2. +1 −1 samples/example1.lua
  3. +4 −12 samples/example2.lua
  4. +4 −12 samples/example3.lua
  5. +1 −1 samples/example4a.lua
  6. +8 −12 samples/example4b.lua
  7. +3 −8 samples/example5a.lua
  8. +3 −8 samples/example5b.lua
  9. +10 −12 src/concurrent/distributed/cookie.lua
  10. +66 −76 src/concurrent/distributed/link.lua
  11. +18 −19 src/concurrent/distributed/message.lua
  12. +36 −37 src/concurrent/distributed/monitor.lua
  13. +107 −124 src/concurrent/distributed/network.lua
  14. +31 −39 src/concurrent/distributed/node.lua
  15. +41 −37 src/concurrent/distributed/process.lua
  16. +152 −134 src/concurrent/distributed/register.lua
  17. +28 −31 src/concurrent/distributed/scheduler.lua
  18. +76 −20 src/concurrent/init.lua
  19. +43 −63 src/concurrent/link.lua
  20. +17 −22 src/concurrent/message.lua
  21. +30 −43 src/concurrent/monitor.lua
  22. +8 −11 src/concurrent/option.lua
  23. +40 −48 src/concurrent/process.lua
  24. +24 −36 src/concurrent/register.lua
  25. +28 −39 src/concurrent/root.lua
  26. +55 −66 src/concurrent/scheduler.lua
  27. +3 −2 test/concurrent.sh
  28. +1 −1 test/concurrent/link1.lua
  29. +1 −1 test/concurrent/link2.lua
  30. +7 −4 test/concurrent/message1.lua
  31. +1 −1 test/concurrent/monitor1.lua
  32. +1 −1 test/concurrent/monitor2.lua
  33. +1 −1 test/concurrent/process1.lua
  34. +1 −1 test/concurrent/process2.lua
  35. +1 −1 test/concurrent/register1.lua
  36. +1 −1 test/concurrent/register2.lua
  37. +1 −1 test/concurrent/trapexit1.lua
  38. +1 −1 test/concurrent/trapexit2.lua
  39. +2 −2 test/distributed/cookie1a.lua
  40. +3 −3 test/distributed/cookie1b.lua
  41. +2 −2 test/distributed/cookie2a.lua
  42. +2 −2 test/distributed/cookie2b.lua
  43. +2 −2 test/distributed/link1a.lua
  44. +2 −2 test/distributed/link1b.lua
  45. +1 −1 test/distributed/link2a.lua
  46. +3 −2 test/distributed/link2b.lua
  47. +2 −2 test/distributed/link2c.lua
  48. +1 −1 test/distributed/message1a.lua
  49. +7 −4 test/distributed/message1b.lua
  50. +2 −2 test/distributed/monitor1a.lua
  51. +2 −2 test/distributed/monitor1b.lua
  52. +1 −1 test/distributed/monitor2a.lua
  53. +3 −2 test/distributed/monitor2b.lua
  54. +2 −2 test/distributed/monitor2c.lua
  55. +1 −1 test/distributed/node1a.lua
  56. +1 −1 test/distributed/node1b.lua
  57. +1 −1 test/distributed/process1a.lua
  58. +1 −1 test/distributed/process1b.lua
  59. +1 −1 test/distributed/process2a.lua
  60. +1 −1 test/distributed/process2b.lua
  61. +1 −1 test/distributed/register1a.lua
  62. +1 −1 test/distributed/register1b.lua
  63. +1 −1 test/distributed/register2a.lua
  64. +1 −1 test/distributed/register2b.lua
  65. +1 −1 test/distributed/register2c.lua
  66. +1 −1 test/distributed/trapexit1a.lua
  67. +1 −1 test/distributed/trapexit1b.lua
  68. +1 −1 test/distributed/trapexit2a.lua
  69. +1 −1 test/distributed/trapexit2b.lua
  70. +1 −1 test/distributed/trapexit2c.lua
  71. +3 −2 test/distributed2a.sh
  72. +3 −2 test/distributed2b.sh
  73. +2 −2 test/distributed3a.sh
  74. +2 −2 test/distributed3b.sh
  75. +2 −2 test/distributed3c.sh
View
@@ -151,7 +151,7 @@ <h3>Creating processes</h3>
just prints a message as many times as specified:</p>
<div class="verbatim"><pre>
-require 'concurrent'
+concurrent = require 'concurrent'
function hello_world(times)
for i = 1, times do print('hello world') end
@@ -173,7 +173,7 @@ <h3>Creating processes</h3>
<p>First the system is loaded:</p>
<div class="verbatim"><pre>
-require 'concurrent'</pre></div>
+concurrent = require 'concurrent'</pre></div>
<p>The function that the process will execute is defined next:</p>
@@ -203,7 +203,7 @@ <h3>Exchanging messages</h3>
then terminate:</p>
<div class="verbatim"><pre>
-require 'concurrent'
+concurrent = require 'concurrent'
function pong()
while true do
@@ -220,19 +220,11 @@ <h3>Exchanging messages</h3>
function ping(n, pid)
for i = 1, n do
- concurrent.send(pid, {
- from = concurrent.self(),
- body = 'ping'
- })
+ concurrent.send(pid, { from = concurrent.self(), body = 'ping' })
local msg = concurrent.receive()
- if msg.body == 'pong' then
- print('ping received pong')
- end
+ if msg.body == 'pong' then print('ping received pong') end
end
- concurrent.send(pid, {
- from = concurrent.self(),
- body = 'finished'
- })
+ concurrent.send(pid, { from = concurrent.self(), body = 'finished' })
print('ping finished')
end
@@ -263,10 +255,7 @@ <h3>Exchanging messages</h3>
<p>The <em>ping</em> process sends a message:</p>
<div class="verbatim"><pre>
-concurrent.send(pid, {
- from = concurrent.self(),
- body = 'ping'
-})</pre></div>
+concurrent.send(pid, { from = concurrent.self(), body = 'ping' })</pre></div>
<p>The <em>pong</em> process waits for a message to arrive and saves it in a
variable when it does:</p>
@@ -277,7 +266,7 @@ <h3>Exchanging messages</h3>
<p>The <em>pong</em> process replies:</p>
<div class="verbatim"><pre>
- concurrent.send(msg.from, { body = 'pong' })</pre></div>
+concurrent.send(msg.from, { body = 'pong' })</pre></div>
<p>The <em>pong</em> process terminates after having received a notification
from the <em>ping</em> process.</p>
@@ -290,7 +279,7 @@ <h3>Registering process names</h3>
<div class="verbatim">
<pre>
-require 'concurrent'
+concurrent = require 'concurrent'
function pong()
while true do
@@ -307,19 +296,11 @@ <h3>Registering process names</h3>
function ping(n)
for i = 1, n do
- concurrent.send('pong', {
- from = concurrent.self(),
- body = 'ping'
- })
+ concurrent.send('pong', { from = concurrent.self(), body = 'ping' })
local msg = concurrent.receive()
- if msg.body == 'pong' then
- print('ping received pong')
- end
+ if msg.body == 'pong' then print('ping received pong') end
end
- concurrent.send('pong', {
- from = concurrent.self(),
- body = 'finished'
- })
+ concurrent.send('pong', { from = concurrent.self(), body = 'finished' })
print('ping finished')
end
@@ -333,18 +314,13 @@ <h3>Registering process names</h3>
<em>ping</em> process sends messages to:</p>
<div class="verbatim"><pre>
-concurrent.send('pong', {
- from = concurrent.self(),
- body = 'ping'
-})</pre></div>
+concurrent.send('pong', { from = concurrent.self(), body = 'ping' })</pre></div>
<p>And:</p>
<div class="verbatim"><pre>
-concurrent.send('pong', {
- from = concurrent.self(),
- body = 'finished'
-})</pre></div>
+concurrent.send('pong', { from = concurrent.self(), body = 'finished' })</pre>
+ </div>
<p>And the <em>pong</em> process now registers its name:</p>
@@ -364,7 +340,7 @@ <h3>Distributed message passing</h3>
<p>The code for the <em>pong</em> process:</p>
<div class="verbatim"><pre>
-require 'concurrent'
+concurrent = require 'concurrent'
function pong()
while true do
@@ -390,23 +366,19 @@ <h3>Distributed message passing</h3>
<p>And the code for the <em>ping</em> process:</p>
<div class="verbatim"><pre>
-require 'concurrent'
+concurrent = require 'concurrent'
function ping(n)
for i = 1, n do
- concurrent.send({ 'pong', 'pong@gaia' }, {
- from = { concurrent.self(), concurrent.node() },
- body = 'ping'
- })
+ concurrent.send({ 'pong', 'pong@gaia' },
+ { from = { concurrent.self(), concurrent.node() },
+ body = 'ping' })
local msg = concurrent.receive()
- if msg.body == 'pong' then
- print('ping received pong')
- end
+ if msg.body == 'pong' then print('ping received pong') end
end
- concurrent.send({ 'pong', 'pong@gaia' }, {
- from = { concurrent.self(), concurrent.node() },
- body = 'finished'
- })
+ concurrent.send({ 'pong', 'pong@gaia' },
+ { from = { concurrent.self(), concurrent.node() },
+ body = 'finished' })
print('ping finished')
end
@@ -462,18 +434,16 @@ <h3>Distributed message passing</h3>
on:</p>
<div class="verbatim"><pre>
-concurrent.send({ 'pong', 'pong@gaia' }, {
- from = { concurrent.self(), concurrent.node() },
- body = 'ping'
-})</pre></div>
+concurrent.send({ 'pong', 'pong@gaia' },
+ { from = { concurrent.self(), concurrent.node() },
+ body = 'ping' })</pre></div>
<p>And later:</p>
<div class="verbatim"><pre>
-concurrent.send({ 'pong', 'pong@gaia' }, {
- from = { concurrent.self(), concurrent.node() },
- body = 'finished'
-})</pre></div>
+concurrent.send({ 'pong', 'pong@gaia' },
+ { from = { concurrent.self(), concurrent.node() },
+ body = 'finished' })</pre></div>
<h3>Handling error</h3>
@@ -483,19 +453,14 @@ <h3>Handling error</h3>
be used to link processes:</p>
<div class="verbatim"><pre>
-require 'concurrent'
+concurrent = require 'concurrent'
function ping(n, pid)
concurrent.link(pid)
for i = 1, n do
- concurrent.send(pid, {
- from = concurrent.self(),
- body = 'ping'
- })
+ concurrent.send(pid, { from = concurrent.self(), body = 'ping' })
local msg = concurrent.receive()
- if msg.body == 'pong' then
- print('ping received pong')
- end
+ if msg.body == 'pong' then print('ping received pong') end
end
print('ping finished')
concurrent.exit('finished')
@@ -546,7 +511,7 @@ <h3>Handling error</h3>
this case a special message is received:</p>
<div class="verbatim"><pre>
-require 'concurrent'
+concurrent = require 'concurrent'
concurrent.setoption('trapexit', true)
@@ -566,14 +531,9 @@ <h3>Handling error</h3>
function ping(n, pid)
concurrent.link(pid)
for i = 1, n do
- concurrent.send(pid, {
- from = concurrent.self(),
- body = 'ping'
- })
+ concurrent.send(pid, { from = concurrent.self(), body = 'ping' })
local msg = concurrent.receive()
- if msg.body == 'pong' then
- print('ping received pong')
- end
+ if msg.body == 'pong' then print('ping received pong') end
end
print('ping finished')
concurrent.exit('finished')
View
@@ -1,4 +1,4 @@
-require 'concurrent'
+concurrent = require 'concurrent'
function hello_world(times)
for i = 1, times do print('hello world') end
View
@@ -1,4 +1,4 @@
-require 'concurrent'
+concurrent = require 'concurrent'
function pong()
while true do
@@ -15,19 +15,11 @@ end
function ping(n, pid)
for i = 1, n do
- concurrent.send(pid, {
- from = concurrent.self(),
- body = 'ping'
- })
+ concurrent.send(pid, { from = concurrent.self(), body = 'ping' })
local msg = concurrent.receive()
- if msg.body == 'pong' then
- print('ping received pong')
- end
+ if msg.body == 'pong' then print('ping received pong') end
end
- concurrent.send(pid, {
- from = concurrent.self(),
- body = 'finished'
- })
+ concurrent.send(pid, { from = concurrent.self(), body = 'finished' })
print('ping finished')
end
View
@@ -1,4 +1,4 @@
-require 'concurrent'
+concurrent = require 'concurrent'
function pong()
while true do
@@ -15,19 +15,11 @@ end
function ping(n)
for i = 1, n do
- concurrent.send('pong', {
- from = concurrent.self(),
- body = 'ping'
- })
+ concurrent.send('pong', { from = concurrent.self(), body = 'ping' })
local msg = concurrent.receive()
- if msg.body == 'pong' then
- print('ping received pong')
- end
+ if msg.body == 'pong' then print('ping received pong') end
end
- concurrent.send('pong', {
- from = concurrent.self(),
- body = 'finished'
- })
+ concurrent.send('pong', { from = concurrent.self(), body = 'finished' })
print('ping finished')
end
View
@@ -1,4 +1,4 @@
-require 'concurrent'
+concurrent = require 'concurrent'
function pong()
while true do
View
@@ -1,20 +1,16 @@
-require 'concurrent'
+concurrent = require 'concurrent'
function ping(n)
for i = 1, n do
- concurrent.send({ 'pong', 'pong@gaia' }, {
- from = { concurrent.self(), concurrent.node() },
- body = 'ping'
- })
+ concurrent.send({ 'pong', 'pong@gaia' },
+ { from = { concurrent.self(), concurrent.node() },
+ body = 'ping' })
local msg = concurrent.receive()
- if msg.body == 'pong' then
- print('ping received pong')
- end
+ if msg.body == 'pong' then print('ping received pong') end
end
- concurrent.send({ 'pong', 'pong@gaia' }, {
- from = { concurrent.self(), concurrent.node() },
- body = 'finished'
- })
+ concurrent.send({ 'pong', 'pong@gaia' },
+ { from = { concurrent.self(), concurrent.node() },
+ body = 'finished' })
print('ping finished')
end
View
@@ -1,16 +1,11 @@
-require 'concurrent'
+concurrent = require 'concurrent'
function ping(n, pid)
concurrent.link(pid)
for i = 1, n do
- concurrent.send(pid, {
- from = concurrent.self(),
- body = 'ping'
- })
+ concurrent.send(pid, { from = concurrent.self(), body = 'ping' })
local msg = concurrent.receive()
- if msg.body == 'pong' then
- print('ping received pong')
- end
+ if msg.body == 'pong' then print('ping received pong') end
end
print('ping finished')
concurrent.exit('finished')
View
@@ -1,4 +1,4 @@
-require 'concurrent'
+concurrent = require 'concurrent'
concurrent.setoption('trapexit', true)
@@ -18,14 +18,9 @@ end
function ping(n, pid)
concurrent.link(pid)
for i = 1, n do
- concurrent.send(pid, {
- from = concurrent.self(),
- body = 'ping'
- })
+ concurrent.send(pid, { from = concurrent.self(), body = 'ping' })
local msg = concurrent.receive()
- if msg.body == 'pong' then
- print('ping received pong')
- end
+ if msg.body == 'pong' then print('ping received pong') end
end
print('ping finished')
concurrent.exit('finished')
Oops, something went wrong.

0 comments on commit c695101

Please sign in to comment.