jbe/bsw@0: function convert.to_human(value, typ) jbe/bsw@0: if value == nil then return "" end -- TODO: is this correct? jbe/bsw@0: if typ and not atom.has_type(value, typ) then jbe/bsw@0: error("The value passed to convert.to_human(...) has not the specified type.") jbe/bsw@0: end jbe/bsw@0: local type_symbol jbe/bsw@0: local value_type = type(value) jbe/bsw@0: if value_type ~= "table" and value_type ~= "userdata" then jbe/bsw@0: type_symbol = value_type jbe/bsw@0: else jbe/bsw@0: type_symbol = convert._type_symbol_mappings[getmetatable(value)] jbe/bsw@0: end jbe/bsw@0: if not type_symbol then jbe/bsw@0: error("Unrecognized type reference occurred in convert.to_human(...).") jbe/bsw@0: end jbe/bsw@0: local converter = convert["_from_" .. type_symbol .. "_to_human"] jbe/bsw@0: if not converter then jbe/bsw@0: error("Type reference in convert.from_human(...) could be recognized, but the converter function is not existent.") jbe/bsw@0: end jbe/bsw@0: return converter(value) jbe/bsw@0: end