seqlua

diff README @ 19:2fad7f50076b

Added coroutine based filter(func, ...) example to new file seqlua_ipairs_example.lua
author jbe
date Wed Aug 20 12:23:31 2014 +0200 (2014-08-20)
parents 431fa6946a61
children 50c6388d4963
line diff
     1.1 --- a/README	Wed Aug 20 06:47:14 2014 +0200
     1.2 +++ b/README	Wed Aug 20 12:23:31 2014 +0200
     1.3 @@ -36,12 +36,12 @@
     1.4      --  2   b
     1.5      --  3   c
     1.6  
     1.7 -    function alphabet(from, to)
     1.8 +    function alphabet()
     1.9        local letter = nil
    1.10        return function()
    1.11          if letter == nil then
    1.12 -          letter = from
    1.13 -        elseif letter == to then
    1.14 +          letter = "a"
    1.15 +        elseif letter == "z" then
    1.16            return nil
    1.17          else
    1.18            letter = string.char(string.byte(letter) + 1)
    1.19 @@ -63,40 +63,6 @@
    1.20      --  25  y
    1.21      --  26  z
    1.22  
    1.23 -    c = setmetatable(
    1.24 -      { iter = alphabet("a", "f") },
    1.25 -      { __call = function(t) return t.iter() end }
    1.26 -    )
    1.27 -
    1.28 -    for i, v in ipairs(c) do
    1.29 -      print(i, v)
    1.30 -    end
    1.31 -    -- prints:
    1.32 -    --  1   a
    1.33 -    --  2   b
    1.34 -    --  3   c
    1.35 -    --  4   d
    1.36 -    --  5   e
    1.37 -    --  6   f
    1.38 -
    1.39 -    g = coroutine.wrap(function()
    1.40 -      coroutine.yield("Alice")
    1.41 -      coroutine.yield("Bob")
    1.42 -      for i = 1, 3 do
    1.43 -        coroutine.yield("Person #" .. tostring(i))
    1.44 -      end
    1.45 -    end)
    1.46 -
    1.47 -    for i, v in ipairs(g) do
    1.48 -      print(i, v)
    1.49 -    end
    1.50 -    -- prints:
    1.51 -    --  1   Alice
    1.52 -    --  2   Bob
    1.53 -    --  3   Person #1
    1.54 -    --  4   Person #2
    1.55 -    --  5   Person #3
    1.56 -
    1.57      set = {apple = true, banana = true}
    1.58      for i, k, v in ipairs(pairs(set)) do
    1.59        print(i, k, v)
    1.60 @@ -106,6 +72,9 @@
    1.61      --  2   apple   true
    1.62      -- (order of "apple" and "banana" may vary)
    1.63  
    1.64 +More examples for invoking the ``ipairs(...)`` function can be found in the
    1.65 +file ``seqlua_ipairs_example.lua``.
    1.66 +
    1.67  The function ``iterator(...)`` may be used to convert any table, any function,
    1.68  or any iterator triplet into a single function (possibly creating a closure):
    1.69  

Impressum / About Us