webmcp
view framework/env/encode/format_options.lua @ 53:a1c77838c2e5
Documentation for "attr", "a_attr" and "form_attr" arguments to function ui.link{...}
author | jbe |
---|---|
date | Fri Jun 10 15:32:29 2011 +0200 (2011-06-10) |
parents | 9fdfb27f8e67 |
children |
line source
1 --[[--
2 string = -- part of string to be used as __format information
3 encode.format_options(
4 params -- arguments for format function
5 )
7 This function is used by encode.format_info(...).
9 --]]--
11 function encode.format_options(params)
12 local params = params or {}
13 local result_parts = {}
14 for key, value in pairs(params) do
15 if type(key) == "string" then
16 if string.find(key, "^[A-Za-z][A-Za-z0-9_]*$") then
17 table.insert(result_parts, "-")
18 table.insert(result_parts, key)
19 table.insert(result_parts, "-")
20 local t = type(value)
21 if t == "string" then
22 value = string.gsub(value, "\\", "\\\\")
23 value = string.gsub(value, "'", "\\'")
24 table.insert(result_parts, "'")
25 table.insert(result_parts, value)
26 table.insert(result_parts, "'")
27 elseif t == "number" then
28 table.insert(result_parts, tostring(value))
29 elseif t == "boolean" then
30 table.insert(result_parts, value and "true" or "false")
31 else
32 error("Format parameter table contained value of unsupported type " .. t .. ".")
33 end
34 else
35 error('Format parameter table contained invalid key "' .. key .. '".')
36 end
37 end
38 end
39 return table.concat(result_parts)
40 end