annotate 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 |
|
rev |
line source |
jbe/bsw@0
|
1 --[[--
|
jbe/bsw@0
|
2 string = -- part of string to be used as __format information
|
jbe/bsw@0
|
3 encode.format_options(
|
jbe/bsw@0
|
4 params -- arguments for format function
|
jbe/bsw@0
|
5 )
|
jbe/bsw@0
|
6
|
jbe/bsw@0
|
7 This function is used by encode.format_info(...).
|
jbe/bsw@0
|
8
|
jbe/bsw@0
|
9 --]]--
|
jbe/bsw@0
|
10
|
jbe/bsw@0
|
11 function encode.format_options(params)
|
jbe/bsw@0
|
12 local params = params or {}
|
jbe/bsw@0
|
13 local result_parts = {}
|
jbe/bsw@0
|
14 for key, value in pairs(params) do
|
jbe/bsw@0
|
15 if type(key) == "string" then
|
jbe/bsw@0
|
16 if string.find(key, "^[A-Za-z][A-Za-z0-9_]*$") then
|
jbe/bsw@0
|
17 table.insert(result_parts, "-")
|
jbe/bsw@0
|
18 table.insert(result_parts, key)
|
jbe/bsw@0
|
19 table.insert(result_parts, "-")
|
jbe/bsw@0
|
20 local t = type(value)
|
jbe/bsw@0
|
21 if t == "string" then
|
jbe/bsw@0
|
22 value = string.gsub(value, "\\", "\\\\")
|
jbe/bsw@0
|
23 value = string.gsub(value, "'", "\\'")
|
jbe/bsw@0
|
24 table.insert(result_parts, "'")
|
jbe/bsw@0
|
25 table.insert(result_parts, value)
|
jbe/bsw@0
|
26 table.insert(result_parts, "'")
|
jbe/bsw@0
|
27 elseif t == "number" then
|
jbe/bsw@0
|
28 table.insert(result_parts, tostring(value))
|
jbe/bsw@0
|
29 elseif t == "boolean" then
|
jbe/bsw@0
|
30 table.insert(result_parts, value and "true" or "false")
|
jbe/bsw@0
|
31 else
|
jbe/bsw@0
|
32 error("Format parameter table contained value of unsupported type " .. t .. ".")
|
jbe/bsw@0
|
33 end
|
jbe/bsw@0
|
34 else
|
jbe/bsw@0
|
35 error('Format parameter table contained invalid key "' .. key .. '".')
|
jbe/bsw@0
|
36 end
|
jbe/bsw@0
|
37 end
|
jbe/bsw@0
|
38 end
|
jbe/bsw@0
|
39 return table.concat(result_parts)
|
jbe/bsw@0
|
40 end
|