webmcp
view framework/env/param/get.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 | 32ec28229bb5 |
line source
1 --[[--
2 value = -- value of the parameter casted to the chosen param_type
3 param.get(
4 key, -- name of the parameter
5 param_type -- desired type of the returned value
6 )
8 Either a GET or POST request parameter is returned by this function, or if param.exchange(...) was called before, one of the exchanged parameters is returned. You can specify which type the returned value shall have. If an external request parameter was used and there is another GET or POST parameter with the same name but a "__format" suffix, the parser with the name of the specified format will be automatically used to parse and convert the input value.
10 --]]--
12 function param.get(key, param_type)
13 local param_type = param_type or atom.string
14 if param._exchanged then
15 local value = param._exchanged.params[key]
16 if value ~= nil and not atom.has_type(value, param_type) then
17 error("Parameter has unexpected type.")
18 end
19 return value
20 else
21 local str = cgi.params[key]
22 local format_info = cgi.params[key .. "__format"]
23 if not str then
24 if not format_info then
25 return nil
26 end
27 str = ""
28 end
29 return param._get_parser(format_info, param_type)(str)
30 end
31 end