jbe/bsw@0: --[[-- jbe/bsw@0: for jbe/bsw@0: index, -- index variable counting up from 1 jbe/bsw@0: 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: in jbe/bsw@0: param.iterate( jbe/bsw@0: prefix -- prefix to be followed by an index in square brackets and another key jbe/bsw@0: ) jbe/bsw@0: do jbe/bsw@0: ... jbe/bsw@0: end jbe/bsw@0: jbe/bsw@0: 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: jbe/bsw@0: --]]-- jbe/bsw@0: jbe/bsw@0: function param.iterate(prefix) jbe/bsw@0: local length = param.get(prefix .. "[len]", atom.integer) or 0 jbe/bsw@0: if not atom.is_integer(length) then jbe/bsw@0: error("List length is not a valid integer or nil.") jbe/bsw@0: end jbe/bsw@0: local index = 0 jbe/bsw@0: return function() jbe/bsw@0: index = index + 1 jbe/bsw@0: if index <= length then jbe/bsw@0: return index, prefix .. "[" .. index .. "]" jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: end