```
do -- testing table library with metamethods
local function test (proxy, t)
for i = 1, 10 do
table.insert(proxy, 1, i)
end
assert(#proxy == 10 and #t == 10, tostring(#proxy)..'; '..tostring(#t))
for i = 1, 10 do
assert(t[i] == 11 - i)
end
table.sort(proxy)
for i = 1, 10 do
assert(t[i] == i and proxy[i] == i, i..': '..tostring(proxy[i])..'; '..tostring(t[i]))
end
assert(table.concat(proxy, ",") == "1,2,3,4,5,6,7,8,9,10")
for i = 1, 8 do
assert(table.remove(proxy, 1) == i)
end
assert(#proxy == 2 and #t == 2)
local a, b, c = table.unpack(proxy)
assert(a == 9 and b == 10 and c == nil)
end
-- all virtual
local t = {}
local proxy = setmetatable({}, {
__len = function () return #t end,
__index = t,
__newindex = t,
})
test(proxy, t)
-- only __newindex
local count = 0
t = setmetatable({}, {
__newindex = function (t,k,v) count = count + 1; rawset(t,k,v) end})
test(t, t)
assert(count == 10) -- after first 10, all other sets are not new
-- no __newindex
t = setmetatable({}, {
__index = function (_,k) return k + 1 end,
__len = function (_) return 5 end})
assert(table.concat(t, ";") == "2;3;4;5;6")
end
function check (a, f)
f = f or function (x,y) return x<y end;
for n = #a, 2, -1 do
local cmp = f(a[n], a[n-1])
if cmp then print(tostring(a)..'\n'..n..': "'..tostring(a[n])..'" < "'..tostring(a[n-1])..'"') end
assert(not cmp)
end
end
for b = 1, 2 do
a = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec"}
if b == 2 then a[15] = 'Aaa' a[14] = 'Iii' a[13] = 'Mmm' end
print(#a)
table.sort(a)
check(a)
end
```
what = [[label between local definitions can mix-up their initializations]],
report = [[Karel Tuma, 2016/03/01]],
since = [[5.2]],
fix = nil,
example = [[
do
local k = 0
local x
::foo::
local y -- should be reset to nil after goto, but it is not
assert(not y)
y = true
k = k + 1
if k < 2 then goto foo end
end
]],
patch = [[
--- lparser.c 2015/11/02 16:09:30 2.149
+++ lparser.c 2016/03/03 12:03:37
@@ -1226,7 +1226,7 @@
checkrepeated(fs, ll, label); /* check for repeated labels */
checknext(ls, TK_DBCOLON); /* skip double colon */
/* create new entry for this label */
- l = newlabelentry(ls, ll, label, line, fs->pc);
+ l = newlabelentry(ls, ll, label, line, luaK_getlabel(fs));
skipnoopstat(ls); /* skip other no-op statements */
if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */
/* assume that locals are already out of scope */
]]
}
```
local ref = {
}
for cl in string.gmatch('acdglpsuwxACDGLPSUWX', '.') do
local list = ''
for i = 0, 255 do
if string.match(string.char(i), '%'..cl) then
list = list..i..','
end
end
if ref[cl] then
assert(ref[cl] == list, cl..':\n'..list..'\n'..ref[cl])
else
print(cl..' = "'..list..'",')
end
end
print('+')
```
```
do
local t = os.tmpname()
local f = io.open(t, 'w')
f:write('test')
f:close()
local i = io.input()
for l in io.lines(t) do end
local n = io.input()
assert(n == i, tostring(n).." ~= "..tostring(i))
os.remove(t)
print('+')
end
```
Fix bug with endless loop at not ended \z sequence.
```
local function lexerror (s, err)
local st, msg = load('return ' .. s, '')
if err ~= '<eof>' then err = err .. "'" end
assert(not st and string.find(msg, "near .-" .. err))
end
lexerror("'alo \\z \n\n", "<eof>")
```