From 09de5a74e13b225c2159bd62bef2563bd2a615c2 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 18 May 2018 16:59:16 +0200 Subject: luci-lib-json: support serializing userdata Fixes the following error when attempting to serialize userdata objects: .../json.lua:81: attempt to call local 'parser' (a nil value) Signed-off-by: Jo-Philipp Wich --- libs/luci-lib-json/luasrc/json.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'libs/luci-lib-json/luasrc/json.lua') diff --git a/libs/luci-lib-json/luasrc/json.lua b/libs/luci-lib-json/luasrc/json.lua index f7b57f916c..6d4d752b19 100644 --- a/libs/luci-lib-json/luasrc/json.lua +++ b/libs/luci-lib-json/luasrc/json.lua @@ -181,13 +181,18 @@ function Encoder.parse_iter(self, obj) end end +function Encoder.parse_udata(self, obj) + return self:parse_string(tostring(obj)) +end + Encoder.parsers = { ['nil'] = Encoder.parse_nil, ['table'] = Encoder.parse_iter, ['number'] = Encoder.parse_number, ['string'] = Encoder.parse_string, ['boolean'] = Encoder.parse_bool, - ['function'] = Encoder.parse_iter + ['function'] = Encoder.parse_iter, + ['userdata'] = Encoder.parse_udata, } -- cgit v1.2.3