@@ -68,26 +68,26 @@ function encode_map.table(t)
6868 end
6969 statusVisited [t ] = true
7070 if type (first_val ) == " string" then
71- local key = {}
71+ local keys = {}
7272 for k in next , t do
7373 if type (k ) ~= " string" then
74- error (" invalid table: mixed or invalid key types: " .. k )
74+ error (" invalid table: mixed or invalid key types: " .. tostring ( k ) )
7575 end
76- key [ # key + 1 ] = k
76+ keys [ # keys + 1 ] = k
7777 end
78- table_sort (key )
78+ table_sort (keys )
7979 statusBuilder [# statusBuilder + 1 ] = " {"
8080 statusDep = statusDep + 1
8181 encode_newline ()
8282 do
83- local k = key [1 ]
83+ local k = keys [1 ]
8484 statusBuilder [# statusBuilder + 1 ] = ' "'
8585 statusBuilder [# statusBuilder + 1 ] = encode_string (k )
8686 statusBuilder [# statusBuilder + 1 ] = ' ": '
8787 encode (t [k ])
8888 end
89- for i = 2 , # key do
90- local k = key [i ]
89+ for i = 2 , # keys do
90+ local k = keys [i ]
9191 statusBuilder [# statusBuilder + 1 ] = " ,"
9292 encode_newline ()
9393 statusBuilder [# statusBuilder + 1 ] = ' "'
@@ -103,7 +103,7 @@ function encode_map.table(t)
103103 local max = 0
104104 for k in next , t do
105105 if math_type (k ) ~= " integer" or k <= 0 then
106- error (" invalid table: mixed or invalid key types: " .. k )
106+ error (" invalid table: mixed or invalid key types: " .. tostring ( k ) )
107107 end
108108 if max < k then
109109 max = k
@@ -126,6 +126,11 @@ function encode_map.table(t)
126126 if t [1 ] == nil then
127127 error (" invalid table: sparse array is not supported" )
128128 end
129+ --- @diagnostic disable-next-line : undefined-global
130+ if jit and t [0 ] ~= nil then
131+ -- 0 is the first index in luajit
132+ error (" invalid table: mixed or invalid key types: " .. 0)
133+ end
129134 statusBuilder [# statusBuilder + 1 ] = " ["
130135 statusDep = statusDep + 1
131136 encode_newline ()
@@ -142,7 +147,7 @@ function encode_map.table(t)
142147 if type (k ) == " number" then
143148 error (" invalid table: sparse array is not supported" )
144149 else
145- error (" invalid table: mixed or invalid key types: " .. k )
150+ error (" invalid table: mixed or invalid key types: " .. tostring ( k ) )
146151 end
147152 end
148153 statusDep = statusDep - 1
0 commit comments