webmcp

view framework/env/param/get.lua @ 567:5e3ebe9fd0ce

Added tag v2.2.1 for changeset 3b71fdb3a00d
author jbe
date Wed Apr 28 13:07:52 2021 +0200 (2021-04-28)
parents 32ec28229bb5
children
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 = request.get_param{ name = key }
22 local format_info = request.get_param{ name = 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

Impressum / About Us