seqlua

changeset 12:91b0d0d4c4dd

Added coroutine example to README
author jbe
date Wed Aug 20 05:18:16 2014 +0200 (2014-08-20)
parents 814d42156b14
children 2ef6eb7d17d2
files README
line diff
     1.1 --- a/README	Wed Aug 20 04:54:49 2014 +0200
     1.2 +++ b/README	Wed Aug 20 05:18:16 2014 +0200
     1.3 @@ -78,6 +78,25 @@
     1.4      --  5   e
     1.5      --  6   f
     1.6  
     1.7 +    g = function()
     1.8 +      coroutine.yield("Alice")
     1.9 +      coroutine.yield("Bob")
    1.10 +      for i = 1, 3 do
    1.11 +        coroutine.yield("Person #" .. tostring(i))
    1.12 +      end
    1.13 +    end
    1.14 +    h = coroutine.wrap(g)
    1.15 +
    1.16 +    for i, v in ipairs(h) do
    1.17 +      print(i, v)
    1.18 +    end
    1.19 +    -- prints:
    1.20 +    --  1   Alice
    1.21 +    --  2   Bob
    1.22 +    --  3   Person #1
    1.23 +    --  4   Person #2
    1.24 +    --  5   Person #3
    1.25 +
    1.26      set = {apple = true, banana = true}
    1.27      for i, k, v in ipairs(pairs(set)) do
    1.28        print(i, k, v)

Impressum / About Us