webmcp
view framework/env/param/get_list.lua @ 3:795b764629ca
Version 1.0.3
Important bugfix related to internal forwards (Bug was introduced by the restriction of views with underscore prefix in Version 1.0.2)
Important bugfix related to internal forwards (Bug was introduced by the restriction of views with underscore prefix in Version 1.0.2)
author | jbe |
---|---|
date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) |
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