webmcp

diff framework/env/param/get.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children 32ec28229bb5
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/param/get.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,31 @@
     1.4 +--[[--
     1.5 +value =       -- value of the parameter casted to the chosen param_type
     1.6 +param.get(
     1.7 +  key,        -- name of the parameter
     1.8 +  param_type  -- desired type of the returned value
     1.9 +)
    1.10 +
    1.11 +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.
    1.12 +
    1.13 +--]]--
    1.14 +
    1.15 +function param.get(key, param_type)
    1.16 +  local param_type = param_type or atom.string
    1.17 +  if param._exchanged then
    1.18 +    local value = param._exchanged.params[key]
    1.19 +    if value ~= nil and not atom.has_type(value, param_type) then
    1.20 +      error("Parameter has unexpected type.")
    1.21 +    end
    1.22 +    return value
    1.23 +  else
    1.24 +    local str         = cgi.params[key]
    1.25 +    local format_info = cgi.params[key .. "__format"]
    1.26 +    if not str then
    1.27 +      if not format_info then
    1.28 +        return nil
    1.29 +      end
    1.30 +      str = ""
    1.31 +    end
    1.32 +    return param._get_parser(format_info, param_type)(str)
    1.33 +  end
    1.34 +end

Impressum / About Us