summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-11-29 05:27:11 +0100
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2010-11-29 05:27:11 +0100
commit06613bc6d84de84c7500e03d219ae011729821f5 (patch)
treec988177477857869979ad1acc611cf9456426d69
parent52688e09827ad6d30f21a58e673a9d8499dc8b89 (diff)
Making the ajax dumping system a little bit more robust.
-rw-r--r--lib/ajaxlib.lua14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/ajaxlib.lua b/lib/ajaxlib.lua
index e51d74f..7a8a395 100644
--- a/lib/ajaxlib.lua
+++ b/lib/ajaxlib.lua
@@ -33,6 +33,18 @@ function ajax_escape(str)
return generic_escape(str, ajax_replacements)
end
+local function toajax(val)
+ local t = type(val)
+
+ if t == "nil" or t == "function" or t == "table" then
+ return ""
+ elseif t == "boolean" then
+ return v and "1" or "0"
+ else
+ return val
+ end
+end
+
function ajax_dump_table(t, out)
local k, v, vk, vv
@@ -43,7 +55,7 @@ function ajax_dump_table(t, out)
for k, v in pairs(t) do
out:write(k)
for vk, vv in pairs(v) do
- out:write("|" .. ajax_escape(vk) .. "=" .. ajax_escape(vv))
+ out:write("|" .. ajax_escape(toajax(vk)) .. "=" .. ajax_escape(toajax(vv)))
end
out:write("\n")
end