webmcp

diff framework/env/convert/from_human.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/convert/from_human.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,15 @@
     1.4 +function convert.from_human(str, typ)
     1.5 +  if not typ then
     1.6 +    error("Using convert.from_human(...) to convert a human readable string to an internal data type needs a type to be specified as second parameter.")
     1.7 +  end
     1.8 +  if not str then return nil end  -- TODO: decide, if an error should be raised instead
     1.9 +  local type_symbol = convert._type_symbol_mappings[typ]
    1.10 +  if not type_symbol then
    1.11 +    error("Unrecognized type reference passed to convert.from_human(...).")
    1.12 +  end
    1.13 +  local converter = convert["_from_human_to_" .. type_symbol]
    1.14 +  if not converter then
    1.15 +    error("Type reference passed to convert.from_human(...) was recognized, but the converter function is not existent.")
    1.16 +  end
    1.17 +  return converter(str)
    1.18 +end
    1.19 \ No newline at end of file

Impressum / About Us