aboutsummaryrefslogtreecommitdiff
path: root/ltn012.wiki
diff options
context:
space:
mode:
authorPierre Chapuis <catwell@archlinux.us>2013-01-23 19:03:46 +0100
committerPierre Chapuis <catwell@archlinux.us>2013-01-23 19:03:46 +0100
commiteea1bc04d759e6a0e51c0b008828eaa372790cdb (patch)
treef3a90fe757a668c125ef55bfba2a8e46011bcc75 /ltn012.wiki
parentd548a78e5516bcc85d44f1d419cf53c71d6dcd79 (diff)
downloadluasocket-eea1bc04d759e6a0e51c0b008828eaa372790cdb.tar.gz
luasocket-eea1bc04d759e6a0e51c0b008828eaa372790cdb.tar.bz2
luasocket-eea1bc04d759e6a0e51c0b008828eaa372790cdb.zip
fix use of arg in ltn documentation
Diffstat (limited to 'ltn012.wiki')
-rw-r--r--ltn012.wiki6
1 files changed, 4 insertions, 2 deletions
diff --git a/ltn012.wiki b/ltn012.wiki
index b924dd3..96b13ae 100644
--- a/ltn012.wiki
+++ b/ltn012.wiki
@@ -126,8 +126,9 @@ local function chain2(f1, f2)
126end 126end
127 127
128function filter.chain(...) 128function filter.chain(...)
129 local arg = {...}
129 local f = arg[1] 130 local f = arg[1]
130 for i = 2, table.getn(arg) do 131 for i = 2, #arg do
131 f = chain2(f, arg[i]) 132 f = chain2(f, arg[i])
132 end 133 end
133 return f 134 return f
@@ -235,9 +236,10 @@ end
235We can make these ideas even more powerful if we use a new feature of Lua 5.0: coroutines. Coroutines suffer from a great lack of advertisement, and I am going to play my part here. Just like lexical scoping, coroutines taste odd at first, but once you get used with the concept, it can save your day. I have to admit that using coroutines to implement our file source would be overkill, so let's implement a concatenated source factory instead. 236We can make these ideas even more powerful if we use a new feature of Lua 5.0: coroutines. Coroutines suffer from a great lack of advertisement, and I am going to play my part here. Just like lexical scoping, coroutines taste odd at first, but once you get used with the concept, it can save your day. I have to admit that using coroutines to implement our file source would be overkill, so let's implement a concatenated source factory instead.
236 {{{ 237 {{{
237function source.cat(...) 238function source.cat(...)
239 local arg = {...}
238 local co = coroutine.create(function() 240 local co = coroutine.create(function()
239 local i = 1 241 local i = 1
240 while i <= table.getn(arg) do 242 while i <= #arg do
241 local chunk, err = arg[i]() 243 local chunk, err = arg[i]()
242 if chunk then coroutine.yield(chunk) 244 if chunk then coroutine.yield(chunk)
243 elseif err then return nil, err 245 elseif err then return nil, err