webmcp

view framework/env/param/get_list.lua @ 11:d76a8857ba62

Added ui.partial and other functions, which allow partial content replacement using XMLHttpRequests; Image support for ui.link

Also includes following changes:
- Fix for rocketcgi library to accept POST data content-types, which contain additional charset information.
- Support arrays passed as params to encode.url (only for keys ending with "[]")
- Version information changed to "1.0.7"

Documentation for added functions is not yet complete.
author jbe/bsw
date Fri Feb 12 18:40:22 2010 +0100 (2010-02-12)
parents 9fdfb27f8e67
children 32ec28229bb5
line source
1 --[[--
2 values = -- list of values casted to the chosen param_type
3 param.get_list(
4 key, -- name of the parameter without "[]" suffix
5 param_type, -- desired type of the returned values
6 )
8 Same as param.get(...), but used for parameters which contain a list of values. For external GET/POST parameters the parameter name gets suffixed with "[]".
10 --]]--
12 function param.get_list(key, param_type)
13 local param_type = param_type or atom.string
14 if param._exchanged then
15 local values = param._exchanged.params[key] or {}
16 if type(values) ~= "table" then
17 error("Parameter has unexpected type.")
18 end
19 for idx, value in ipairs(values) do
20 if not atom.has_type(value, param_type) then
21 error("Element of parameter list has unexpected type.")
22 end
23 end
24 return values
25 else
26 local format_info = cgi.params[key .. "__format"]
27 local parser = param._get_parser(format_info, param_type)
28 local raw_values = cgi.params[key .. "[]"]
29 local values = {}
30 if raw_values then
31 for idx, value in ipairs(raw_values) do
32 values[idx] = parser(raw_values[idx])
33 end
34 end
35 return values
36 end
37 end

Impressum / About Us