diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2010-11-29 05:27:11 +0100 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2010-11-29 05:27:11 +0100 |
commit | 06613bc6d84de84c7500e03d219ae011729821f5 (patch) | |
tree | c988177477857869979ad1acc611cf9456426d69 /lib | |
parent | 52688e09827ad6d30f21a58e673a9d8499dc8b89 (diff) |
Making the ajax dumping system a little bit more robust.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ajaxlib.lua | 14 |
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 |