aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorleaf corcoran <leafot@gmail.com>2019-09-21 18:43:47 -0700
committerleaf <leafot@gmail.com>2020-04-25 14:13:42 -0700
commitdcd5c253ce2839c10cc4e40ca98202fc29270762 (patch)
tree27c59ed5b3a3171c828699aac53825b4da6f3a19 /lua
parent3cdf14a8ddd283e9738860359fbdc5ba4e618972 (diff)
downloadlua-cjson-dcd5c253ce2839c10cc4e40ca98202fc29270762.tar.gz
lua-cjson-dcd5c253ce2839c10cc4e40ca98202fc29270762.tar.bz2
lua-cjson-dcd5c253ce2839c10cc4e40ca98202fc29270762.zip
Lua 5.2+ maxn support
Diffstat (limited to 'lua')
-rw-r--r--lua/cjson/util.lua12
1 files changed, 11 insertions, 1 deletions
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"
2 2
3local unpack = unpack or table.unpack 3local unpack = unpack or table.unpack
4 4
5local maxn = table.maxn or function(t)
6 local max = 0
7 for k,v in pairs(t) do
8 if type(k) == "number" and k > max then
9 max = k
10 end
11 end
12 return max
13end
14
5-- Various common routines used by the Lua CJSON package 15-- Various common routines used by the Lua CJSON package
6-- 16--
7-- Mark Pulford <mark@kyne.com.au> 17-- Mark Pulford <mark@kyne.com.au>
@@ -194,7 +204,7 @@ local function run_test(testname, func, input, should_work, output)
194 local result = {} 204 local result = {}
195 local tmp = { pcall(func, unpack(input)) } 205 local tmp = { pcall(func, unpack(input)) }
196 local success = tmp[1] 206 local success = tmp[1]
197 for i = 2, table.maxn(tmp) do 207 for i = 2, maxn(tmp) do
198 result[i - 1] = tmp[i] 208 result[i - 1] = tmp[i]
199 end 209 end
200 210