From 3cc7bb2ea693462e96756bc85ca863e6ca06cf41 Mon Sep 17 00:00:00 2001 From: MoreThanTom Date: Mon, 5 Aug 2019 19:12:52 +0100 Subject: [PATCH 1/2] Use `n` for total number of parameters Since lua 5.2, lua has had an 'official' way of representing a list's length - [table.pack](https://www.lua.org/manual/5.2/manual.html#pdf-table.pack) returns a table with a `n` field containing the total number of parameters --- src/lunajson/encoder.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lunajson/encoder.lua b/src/lunajson/encoder.lua index 606767a..0da99d5 100644 --- a/src/lunajson/encoder.lua +++ b/src/lunajson/encoder.lua @@ -17,7 +17,7 @@ end local _ENV = nil -local function newencoder() +local function newencoder(saxtbl) local v, nullv local i, builder, visited @@ -93,7 +93,7 @@ local function newencoder() end visited[o] = true - local tmp = o[0] + local tmp = o.n if type(tmp) == 'number' then -- arraylen available builder[i] = '[' i = i+1 From c166bd3839baa8c518c8e28535289c09178cb30b Mon Sep 17 00:00:00 2001 From: MoreThanTom Date: Mon, 5 Aug 2019 20:18:36 +0100 Subject: [PATCH 2/2] Update decoder.lua --- src/lunajson/decoder.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lunajson/decoder.lua b/src/lunajson/decoder.lua index 98a0bab..65630fa 100644 --- a/src/lunajson/decoder.lua +++ b/src/lunajson/decoder.lua @@ -392,7 +392,7 @@ local function newdecoder() end if arraylen then -- commit the length of the array if `arraylen` is set - ary[0] = i + ary.n = i end rec_depth = rec_depth - 1 return ary