jbe/bsw@0: --[[-- jbe/bsw@0: text = -- a string jbe/bsw@0: format.string( jbe/bsw@0: value, -- any value where tostring(value) gives a reasonable result jbe/bsw@0: { jbe/bsw@0: nil_as = nil_text -- text to be returned for a nil value jbe/bsw@0: } jbe/bsw@0: ) jbe/bsw@0: jbe/bsw@0: Formats a value as a text by calling tostring(...), unless the value is nil, in which case the text returned is chosen by the 'nil_as' option. jbe/bsw@0: jbe/bsw@0: --]]-- jbe/bsw@0: jbe/bsw@0: function format.string(str, options) jbe/bsw@0: local options = options or {} jbe/bsw@0: if str == nil then jbe/bsw@0: return options.nil_as or "" jbe/bsw@0: else jbe/bsw@0: return tostring(str) jbe/bsw@0: end jbe/bsw@0: end