seqlua

changeset 44:de5e7dd93863

Re-added example for customized iteration behavior
author jbe
date Mon Aug 25 03:59:45 2014 +0200 (2014-08-25)
parents 1a0ce77d9e4b
children 35eb59c51be6
files README
line diff
     1.1 --- a/README	Mon Aug 25 03:51:00 2014 +0200
     1.2 +++ b/README	Mon Aug 25 03:59:45 2014 +0200
     1.3 @@ -111,8 +111,25 @@
     1.4  (as previously shown).
     1.5  
     1.6  Where desired, it is also possible to use metamethods to customize iteration
     1.7 -behavior. This extension, however, doesn't respect the ``__len`` metamethod due
     1.8 -to the following reasons:
     1.9 +behavior:
    1.10 +
    1.11 +    function print_rows(rows)
    1.12 +      for i, row in ipairs(rows) do
    1.13 +        print_row(row)
    1.14 +      end
    1.15 +    end
    1.16 +    local result = sql_query("SELECT * FROM actor ORDER BY birthday")
    1.17 +
    1.18 +    -- we may rely on the ``__index`` or ``__ipairs`` metamethod to
    1.19 +    -- iterate through all result rows here:
    1.20 +    print_rows(result)  -- no need to use ":rows()" or a similar syntax
    1.21 +
    1.22 +    -- but we can also still pass individual result rows to the
    1.23 +    -- print_rows function:
    1.24 +    print_rows{result[1], result[#result]}
    1.25 +
    1.26 +This extension, however, doesn't respect the ``__len`` metamethod due to the
    1.27 +following reasons:
    1.28  
    1.29  * An efficient implementation where ``for i, v in ipairs(tbl) do ... end`` does
    1.30    neither create a closure nor repeatedly evaluate ``#tbl`` seems to be

Impressum / About Us