From dcd5c253ce2839c10cc4e40ca98202fc29270762 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Sat, 21 Sep 2019 18:43:47 -0700 Subject: Lua 5.2+ maxn support --- lua/cjson/util.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/cjson/util.lua b/lua/cjson/util.lua index 48fa33c..2405257 100644 --- a/lua/cjson/util.lua +++ b/lua/cjson/util.lua @@ -2,6 +2,16 @@ local json = require "cjson" local unpack = unpack or table.unpack +local maxn = table.maxn or function(t) + local max = 0 + for k,v in pairs(t) do + if type(k) == "number" and k > max then + max = k + end + end + return max +end + -- Various common routines used by the Lua CJSON package -- -- Mark Pulford @@ -194,7 +204,7 @@ local function run_test(testname, func, input, should_work, output) local result = {} local tmp = { pcall(func, unpack(input)) } local success = tmp[1] - for i = 2, table.maxn(tmp) do + for i = 2, maxn(tmp) do result[i - 1] = tmp[i] end -- cgit v1.2.3-55-g6feb