seqlua

changeset 21:eb40d8ea7b9a

Undo previous commit (doesn't work more than once)
author jbe
date Wed Aug 20 12:57:53 2014 +0200 (2014-08-20)
parents ed7a82f85e6f
children 50c6388d4963
files seqlua_ipairs_example.lua
line diff
     1.1 --- a/seqlua_ipairs_example.lua	Wed Aug 20 12:47:33 2014 +0200
     1.2 +++ b/seqlua_ipairs_example.lua	Wed Aug 20 12:57:53 2014 +0200
     1.3 @@ -71,13 +71,13 @@
     1.4  --  4   Person #2
     1.5  --  5   Person #3
     1.6  
     1.7 -function create_filter(f)
     1.8 -  return coroutine.wrap(function(...)
     1.9 -    for i, v in ipairs(...) do f(v) end
    1.10 +function filter(f, iter, iter_s, iter_i)
    1.11 +  return coroutine.wrap(function()
    1.12 +    for i, v in ipairs(iter, iter_s, iter_i) do f(v) end
    1.13    end)
    1.14  end
    1.15  
    1.16 -my_filter = create_filter(function(v)
    1.17 +function filterfunc(v)
    1.18    local type_v = type(v)
    1.19    if type_v == "string" then
    1.20      coroutine.yield(v)
    1.21 @@ -86,9 +86,9 @@
    1.22        coroutine.yield(true)
    1.23      end
    1.24    end
    1.25 -end)
    1.26 +end
    1.27  
    1.28 -for v in my_filter, {"a", "b", 3, "c"} do  -- no closure is created
    1.29 +for v in filter(filterfunc, {"a", "b", 3, "c"}) do
    1.30    print(v)
    1.31  end
    1.32  -- prints:

Impressum / About Us