webmcp
annotate framework/env/encode/format_options.lua @ 28:ea2e8f3a2776
allow webmcp path to be set in cgi script
this allows another script to include the webmcp script when the cwd is not the cgi-bin. the script needs to set the WEBMCP_PATH variable.
this allows another script to include the webmcp script when the cwd is not the cgi-bin. the script needs to set the WEBMCP_PATH variable.
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Sun Sep 19 01:36:08 2010 +0200 (2010-09-19) |
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 |