webmcp
view framework/env/encode/format_options.lua @ 2:72860d232f32
Version 1.0.2
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
author | jbe/bsw |
---|---|
date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-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