webmcp
view framework/env/param/iterate.lua @ 2:72860d232f32
Version 1.0.2
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
| author | jbe/bsw | 
|---|---|
| date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) | 
| parents | 9fdfb27f8e67 | 
| children | 
 line source
     1 --[[--
     2 for
     3   index,          -- index variable counting up from 1
     4   prefix          -- prefix string with index in square brackets to be used as a prefix for a key passed to param.get or param.get_list
     5 in
     6   param.iterate(
     7     prefix        -- prefix to be followed by an index in square brackets and another key
     8   )
     9 do
    10   ...
    11 end
    13 This function returns an interator function to be used in a for loop. The CGI GET/POST parameter (or internal parameter) with the name "prefix[len]" is read, where 'prefix' is the prefix passed as the argument and 'len' ist just the literal string "len". For each index from 1 to the read length the returned iterator function returns the index and a string consisting of the given prefix followed by the index in square brackets to be used as a prefix for keys passed to param.get(...) or param.get_list(...).
    15 --]]--
    17 function param.iterate(prefix)
    18   local length = param.get(prefix .. "[len]", atom.integer) or 0
    19   if not atom.is_integer(length) then
    20     error("List length is not a valid integer or nil.")
    21   end
    22   local index = 0
    23   return function()
    24     index = index + 1
    25     if index <= length then
    26       return index, prefix .. "[" .. index .. "]"
    27     end
    28   end
    29 end
