-
Notifications
You must be signed in to change notification settings - Fork 1
/
coro.html
127 lines (120 loc) · 6.26 KB
/
coro.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title> coro - symmetric coroutines </title>
<script src="jquery.js"></script>
<script src="jquery-cookie.js"></script>
<script src="jquery-tablesorter.js"></script>
<script src="strftime.js"></script>
<script src="mustache.js"></script>
<script src="config.js"></script>
<script src="main.js"></script>
<link rel="stylesheet" type="text/css" href="templates/reset.css" />
<link rel="stylesheet" type="text/css" href="templates/hack.css" />
<link rel="stylesheet" type="text/css" id="lights_css" />
<script>
var DOCNAME = 'coro'
var PROJECT = 'coro'
//set the lights before rendering starts
set_lights()
</script>
</head>
<body>
<header>
<div class="container">
<div class="btn-container btn-lights-container">
<a href="#" class="btn btn-lights" id="lights">lights</a>
</div>
<div class="btn-container btn-home-container">
<a href="/" class="btn btn-home">luapower</a>
</div>
<table id="header_table">
<tr>
<td style="vertical-align: middle;" width="100%">
<h1> coro </h1>
<h2> symmetric coroutines </h2>
</td>
<td style="vertical-align: middle;" align="right" style="height: 150px">
<table><tr><td>
<div class="doc" id="package_info_container">
<div id="package_info"> </div>
<div id="commit_log"> </div>
</div>
<a href="https://github.com/luapower/coro" class="btn btn-rightside btn-github"><span class="icon"></span>View on GitHub</a>
</td></tr><tr><td>
<a href="https://github.com/luapower/coro/tarball/master" class="btn btn-rightside">Download as .tar.gz</a>
</td></tr><tr><td>
<a href="https://github.com/luapower/coro/zipball/master" class="btn btn-rightside">Download as .zip</a>
</td></tr></table>
</td>
</tr>
</table>
<div class="btn-container btn-discuss-container">
<a href="https://github.com/luapower/coro/issues/new" target="_blank"
class="btn btn-rightside btn-discuss"><span class="icon"></span>Discuss</a>
</div>
</div>
</header>
<div class="bg-container">
<div class="bg-center-container">
<div class="bg bg-coro" style="background-image: url('bg/coro.png');"></div>
</div>
</div>
<div class="under-header">
<div class="container">
<div id="toc_container" class="toc_container doc"></div>
<button id=tab1_button class="tab_button hidden">Documentation</button>
<button id=tab2_button class="tab_button hidden">Package Info</button>
<div id="tabs_cointainer">
<div id="tab1_container">
<section class="doc">
<span id="module_info"></span>
<h2 id="local-coro-requirecoro"><code>local coro = require'coro'</code></h2>
<p>Symmetric coroutines are coroutines that allow you to transfer control to a specific coroutine, unlike Lua's standard coroutines which only allow you to suspend execution to the calling coroutine.</p>
<p>This is the implementation from the paper <a href="http://www.inf.puc-rio.br/~roberto/docs/corosblp.pdf">Coroutines in Lua</a>.</p>
<p>Changes from the paper:</p>
<ul>
<li>threads created with <code>coro.create()</code> finish into the creator thread not main thread, unless otherwise specified.</li>
<li>added <code>coro.wrap()</code> similar to <code>coroutine.wrap()</code>.</li>
</ul>
<h2 id="coro.createf-return_thread---coro_thread"><code>coro.create(f[, return_thread]) -> coro_thread</code></h2>
<p>Create a symmetric coroutine, optionally specifying the thread which the coroutine should transfer control to when it finishes execution (defaults to <code>coro.current</code>.</p>
<h2 id="coro.transfercoro_thread-send_val---recv_val"><code>coro.transfer(coro_thread[, send_val]) -> recv_val</code></h2>
<p>Transfer control to a symmetric coroutine, suspending execution. The target coroutine either hasn't started yet, or it is itself suspended in a call to <code>coro.transfer()</code>, in which case it resumes and receives <code>send_val</code> as the return value of the call. Likewise, the coroutine which transfers execution will stay suspended until <code>coro.transfer()</code> is called again with it as target.</p>
<h2 id="coro.current---coro_thread"><code>coro.current -> coro_thread</code></h2>
<p>Currently running symmetric coroutine. Defaults to <code>coro.main</code>.</p>
<h2 id="coro.main---coro_thread"><code>coro.main -> coro_thread</code></h2>
<p>The coroutine representing the main thread (the thread that calls <code>coro.transfer</code> for the first time).</p>
<h2 id="coro.wrapf---f"><code>coro.wrap(f) -> f</code></h2>
<p>Similar to <code>coroutine.wrap</code> for symmetric coroutines. Useful for creating iterators in an environment of symmetric coroutines in which simply calling <code>coroutine.yield</code> is not an option:</p>
<pre class="sourceCode lua"><code class="sourceCode lua"><span class="kw">local</span> <span class="kw">parent</span> <span class="ot">=</span> <span class="kw">coro</span><span class="ot">.</span><span class="kw">current</span>
<span class="kw">local</span> <span class="kw">iter</span> <span class="ot">=</span> <span class="kw">coro</span><span class="ot">.</span>wrap<span class="ot">(</span><span class="kw">function</span><span class="ot">()</span>
<span class="kw">local</span> <span class="kw">function</span> yield<span class="ot">(</span><span class="kw">val</span><span class="ot">)</span>
<span class="kw">coro</span><span class="ot">.</span>transfer<span class="ot">(</span><span class="kw">parent</span><span class="ot">,</span> <span class="kw">val</span><span class="ot">)</span>
<span class="kw">end</span>
<span class="ot">...</span>
yield<span class="ot">(</span><span class="kw">val</span><span class="ot">)</span>
<span class="kw">end</span><span class="ot">)</span></code></pre>
</section>
</div>
<div id="tab2_container" class="doc"></div>
</div>
</div>
<div class="container">
<footer>
<div id="disqus_thread"></div>
<div class="faint">[email protected] | <a href="http://unlicense.org/">public domain</a></div>
</footer>
</div>
</div>
<script type="text/x-mustache" id=info_tab_template>
<h3>Modules</h3>
<ul>
{{#module_array}}
<li>{{name}}</li>
{{/module_array}}
</ul>
</script>
</body>
</html>