webmcp

view framework/env/encode/format_options.lua @ 562:328f120924a2

Removed if-clause when initializing file descriptor set to avoid compiler warning for mondelefant_conn_try_wait
author jbe
date Fri Feb 05 15:51:39 2021 +0100 (7 months ago)
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

Impressum / About Us