diff options
author | Steven Barth <steven@midlink.org> | 2008-08-29 13:44:33 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-08-29 13:44:33 +0000 |
commit | b6e397e1a42022631fb17a7ef33f854040398ae3 (patch) | |
tree | 5c6d9a730c9847351fb278f6cb0ee3260ae567ab /libs | |
parent | bda994c32e8afda1cac2e0e4ae4c66c50d82c3f1 (diff) |
Optimized encoding of arrays containing nil values
Optimized inline documentation
Diffstat (limited to 'libs')
-rw-r--r-- | libs/json/luasrc/json.lua | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/libs/json/luasrc/json.lua b/libs/json/luasrc/json.lua index 3f66b8332..5d1abcf48 100644 --- a/libs/json/luasrc/json.lua +++ b/libs/json/luasrc/json.lua @@ -56,6 +56,7 @@ local next = next local getmetatable = getmetatable --- LuCI JSON-Library +-- @cstyle instance module "luci.json" --- Null replacement function @@ -64,16 +65,15 @@ function null() return null end ---- JSON-Encoder --- @class module --- @cstyle instance --- @name luci.json.Encoder -Encoder = util.class() - ---- Creates a new Encoder. +--- Create a new JSON-Encoder. +-- @class function +-- @name Encoder -- @param data Lua-Object to be encoded. -- @param buffersize Blocksize of returned data source. -- @param fastescape Use non-standard escaping (don't escape control chars) +-- @return JSON-Encoder +Encoder = util.class() + function Encoder.__init__(self, data, buffersize, fastescape) self.data = data self.buffersize = buffersize or 512 @@ -184,10 +184,10 @@ function Encoder.parse_iter(self, obj) local first = true if type(obj) == "table" then - for i, entry in pairs(obj) do + for i=1, #obj do first = first or self:put(",") first = first and nil - self:dispatch(entry) + self:dispatch(obj[i]) end else for entry in obj do @@ -211,14 +211,13 @@ Encoder.parsers = { } ---- JSON-Decoder --- @class module --- @cstyle instance --- @name luci.json.Decoder +--- Create a new JSON-Decoder. +-- @class function +-- @name Decoder +-- @param customnull Use luci.json.null instead of nil for decoding null +-- @return JSON-Decoder Decoder = util.class() ---- Create a new Decoder object. --- @param customnull Use luci.json.null instead of nil function Decoder.__init__(self, customnull) self.cnull = customnull getmetatable(self).__call = Decoder.sink |