webmcp
view framework/env/convert/to_human.lua @ 1:985024b16520
Version 1.0.1
New feature: JSON requests
Changes in ui.paginate: Current page setting is directly fetched from CGI params, instead of view params
Changed behavior of load methods of atom library to accept nil as input
Bugfixes in mondelefant_atom_connector timestamp(tz) loaders
Added global constant _WEBMCP_VERSION containing a version string
New feature: JSON requests
Changes in ui.paginate: Current page setting is directly fetched from CGI params, instead of view params
Changed behavior of load methods of atom library to accept nil as input
Bugfixes in mondelefant_atom_connector timestamp(tz) loaders
Added global constant _WEBMCP_VERSION containing a version string
author | jbe |
---|---|
date | Tue Nov 17 12:00:00 2009 +0100 (2009-11-17) |
parents | 9fdfb27f8e67 |
children |
line source
1 function convert.to_human(value, typ)
2 if value == nil then return "" end -- TODO: is this correct?
3 if typ and not atom.has_type(value, typ) then
4 error("The value passed to convert.to_human(...) has not the specified type.")
5 end
6 local type_symbol
7 local value_type = type(value)
8 if value_type ~= "table" and value_type ~= "userdata" then
9 type_symbol = value_type
10 else
11 type_symbol = convert._type_symbol_mappings[getmetatable(value)]
12 end
13 if not type_symbol then
14 error("Unrecognized type reference occurred in convert.to_human(...).")
15 end
16 local converter = convert["_from_" .. type_symbol .. "_to_human"]
17 if not converter then
18 error("Type reference in convert.from_human(...) could be recognized, but the converter function is not existent.")
19 end
20 return converter(value)
21 end