webmcp
diff framework/env/format/string.lua @ 0:9fdfb27f8e67
Version 1.0.0
author | jbe/bsw |
---|---|
date | Sun Oct 25 12:00:00 2009 +0100 (2009-10-25) |
parents | |
children | 0c4841af07a5 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/format/string.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,21 @@ 1.4 +--[[-- 1.5 +text = -- a string 1.6 +format.string( 1.7 + value, -- any value where tostring(value) gives a reasonable result 1.8 + { 1.9 + nil_as = nil_text -- text to be returned for a nil value 1.10 + } 1.11 +) 1.12 + 1.13 +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. 1.14 + 1.15 +--]]-- 1.16 + 1.17 +function format.string(str, options) 1.18 + local options = options or {} 1.19 + if str == nil then 1.20 + return options.nil_as or "" 1.21 + else 1.22 + return tostring(str) 1.23 + end 1.24 +end