webmcp

annotate framework/env/param/iterate.lua @ 6:5cba83b3f411

Version 1.0.6

Bugfix: class_prototype:add_reference{...} uses now qualified names in SQL queries to allow JOINs

Fixes in the documentation of slot.put_into and trace.debug
author jbe/bsw
date Fri Jan 22 12:00:00 2010 +0100 (2010-01-22)
parents 9fdfb27f8e67
children
rev   line source
jbe/bsw@0 1 --[[--
jbe/bsw@0 2 for
jbe/bsw@0 3 index, -- index variable counting up from 1
jbe/bsw@0 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
jbe/bsw@0 5 in
jbe/bsw@0 6 param.iterate(
jbe/bsw@0 7 prefix -- prefix to be followed by an index in square brackets and another key
jbe/bsw@0 8 )
jbe/bsw@0 9 do
jbe/bsw@0 10 ...
jbe/bsw@0 11 end
jbe/bsw@0 12
jbe/bsw@0 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(...).
jbe/bsw@0 14
jbe/bsw@0 15 --]]--
jbe/bsw@0 16
jbe/bsw@0 17 function param.iterate(prefix)
jbe/bsw@0 18 local length = param.get(prefix .. "[len]", atom.integer) or 0
jbe/bsw@0 19 if not atom.is_integer(length) then
jbe/bsw@0 20 error("List length is not a valid integer or nil.")
jbe/bsw@0 21 end
jbe/bsw@0 22 local index = 0
jbe/bsw@0 23 return function()
jbe/bsw@0 24 index = index + 1
jbe/bsw@0 25 if index <= length then
jbe/bsw@0 26 return index, prefix .. "[" .. index .. "]"
jbe/bsw@0 27 end
jbe/bsw@0 28 end
jbe/bsw@0 29 end

Impressum / About Us