mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 03:58:21 +01:00
Add ltn12.source.table()
This commit is contained in:
parent
6529598909
commit
8fee636309
@ -405,6 +405,16 @@ Creates and returns a source that produces the contents of a
|
|||||||
<tt>string</tt>, chunk by chunk.
|
<tt>string</tt>, chunk by chunk.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<!-- table +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
|
||||||
|
<p class=name id="source.table">
|
||||||
|
ltn12.source.<b>table(</b>table<b>)</b>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p class=description>
|
||||||
|
Creates and returns a source that produces the numerically-indexed values of a <tt>table</tt> successively beginning at 1. The source returns nil (end-of-stream) whenever a nil value is produced by the current index, which proceeds forward regardless.
|
||||||
|
</p>
|
||||||
|
|
||||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||||
|
|
||||||
<div class=footer>
|
<div class=footer>
|
||||||
|
@ -99,7 +99,8 @@ Support, Manual">
|
|||||||
<a href="ltn12.html#source.error">error</a>,
|
<a href="ltn12.html#source.error">error</a>,
|
||||||
<a href="ltn12.html#source.file">file</a>,
|
<a href="ltn12.html#source.file">file</a>,
|
||||||
<a href="ltn12.html#source.simplify">simplify</a>,
|
<a href="ltn12.html#source.simplify">simplify</a>,
|
||||||
<a href="ltn12.html#source.string">string</a>.
|
<a href="ltn12.html#source.string">string</a>,
|
||||||
|
<a href="ltn12.html#source.table">table</a>.
|
||||||
</blockquote>
|
</blockquote>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
@ -128,6 +128,16 @@ function source.string(s)
|
|||||||
else return source.empty() end
|
else return source.empty() end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- creates table source
|
||||||
|
function source.table(t)
|
||||||
|
base.assert('table' == type(t))
|
||||||
|
local i = 0
|
||||||
|
return function()
|
||||||
|
i = i + 1
|
||||||
|
return t[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- creates rewindable source
|
-- creates rewindable source
|
||||||
function source.rewind(src)
|
function source.rewind(src)
|
||||||
base.assert(src)
|
base.assert(src)
|
||||||
|
@ -180,6 +180,15 @@ assert(ltn12.pump.all(source, sink), "returned error")
|
|||||||
assert(table.concat(t) == s, "mismatch")
|
assert(table.concat(t) == s, "mismatch")
|
||||||
print("ok")
|
print("ok")
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
io.write("testing source.table: ")
|
||||||
|
local inp = {'a','b','c','d','e'}
|
||||||
|
local source = ltn12.source.table(inp)
|
||||||
|
sink, t = ltn12.sink.table()
|
||||||
|
assert(ltn12.pump.all(source, sink), "returned error")
|
||||||
|
for i = 1, #inp do assert(t[i] == inp[i], "mismatch") end
|
||||||
|
print("ok")
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
io.write("testing source.chain (with split): ")
|
io.write("testing source.chain (with split): ")
|
||||||
source = ltn12.source.string(s)
|
source = ltn12.source.string(s)
|
||||||
|
Loading…
Reference in New Issue
Block a user