local smt = getmetatable("")
smt.__len = function() return 99 end
local n = #"abc"
smt.__len = nil
return n
local smt = getmetatable("")
local old = smt.__index
smt.__index = function(s, k) return k .. "!" end
local r = ("abc").foo
smt.__index = old
return r, ("x"):upper()
local log = {}
local f = coroutine.wrap(function()
local x <close> = setmetatable({}, {__close = function(_, e) log[#log + 1] = "closed:" .. tostring(e) end})
coroutine.yield(1)
error("boom", 0)
end)
f()
local ok, e = pcall(f)
return ok, e, log[1]
local r = {}
for i = math.mininteger, math.maxinteger, math.maxinteger do r[#r + 1] = i end
for i = math.maxinteger, math.mininteger, math.mininteger do r[#r + 1] = i end
for i = 0, math.maxinteger, 2^62 do r[#r + 1] = math.type(i) end
for i = -1, -3, -1 do r[#r + 1] = i end
return table.concat(r, " ")
local r = {}
for i = 0.5, 2 do r[#r + 1] = i end
for i = 3, 1.5, -0.5 do r[#r + 1] = i end
return table.concat(r, " ")
local t = {}
t["1"] = "s"; t[1] = "n"
return t["1"], t[1], #t
local t = setmetatable({}, {__newindex = function() error("no") end, __index = function() return "dflt" end})
local r = rawset(t, "k", 1)
return r == t, rawget(t, "k"), t.k, t.missing, rawget(t, "missing")
local t = setmetatable({a = false}, {__index = function() return "meta" end})
return t.a, t.b
local calls = 0
local t = setmetatable({}, {__newindex = function(t, k, v) calls = calls + 1 end})
t.x = nil
return calls
local function f() return 1, nil, 3, nil end
local co = coroutine.wrap(function(...) coroutine.yield(...) return select("#", ...) end)
return select("#", pcall(f)), select("#", co(f())), co()
local e = {}
local ok, got = pcall(function() local ok2, e2 = pcall(error, e) error(e2) end)
return got == e
local function a() error("deep", 3) end
local function b() a() end
local function c() b() end
return pcall(c)
local inner = setmetatable({}, {__tostring = function() return "in" end})
local outer = setmetatable({}, {__tostring = function() return tostring(inner) .. "+out" end})
return tostring(outer), string.format("%s", outer)
return 1 .. 2, 1.5 .. "|", (2^63) .. "", math.mininteger .. "", 1e15 .. "", -1e15 .. ""
return 7 // 2.0, 7 % 2.0, -7 // 2.0, -7 % 2.0, 7.0 // -2, 7.0 % -2, math.type(7 // 2.0)
return math.maxinteger < 2^63, math.maxinteger <= 2^63, math.mininteger <= -2^63, math.mininteger < -2^63, 2^63 > math.maxinteger, -2^63 >= math.mininteger, 1e308 > math.maxinteger, -1e308 < math.mininteger
return math.maxinteger == 2^63, math.maxinteger == 2^63 - 1, math.mininteger == -2^63, 2^53 == (2^53 | 0), 2^53 + 1 == (2^53 | 0) + 1
return string.format("%5.1f|%-8.3e|%+g|%x|%d", 3, 4, 5, 6.0, -0.0)
return ("a.b"):gsub("%.$", "!"), ("a$"):gsub("%$", "D"), ("x^"):gsub("%^", "C"), ("a.b"):gsub(".", "%0", 2)
return ("hello world"):find("(o)(r)"), ("hello"):find("l(l)()"), ("abc"):find("()")
local r = {}
for a, b in ("abc"):gmatch("()(.?)") do r[#r + 1] = a .. "=" .. b end
return table.concat(r, ",")
return pcall(string.rep, "ab", math.maxinteger // 2), pcall(string.rep, "a", math.maxinteger, ",")
return pcall(table.concat, {}, ",", 1, 3), pcall(table.concat, {1, 2}, ",", 2, 1)
return select("2", "a", "b"), pcall(select, "x", 1)
local t = {[1] = "a", [2.5] = "b"}
local n = 0
for k, v in next, t do n = n + 1 end
return n
local t = setmetatable({}, {__index = {"x", "y"}})
local r = {}
for i, v in ipairs(t) do r[#r + 1] = v end
return table.concat(r)
return #utf8.char(0x7F), #utf8.char(0x80), #utf8.char(0x7FF), #utf8.char(0x800), #utf8.char(0xFFFF), #utf8.char(0x10000), #utf8.char(0x1FFFFF), #utf8.char(0x200000), #utf8.char(0x3FFFFFF), #utf8.char(0x4000000)
local s = "a€b"
return utf8.offset(s, -1), utf8.offset(s, -2), utf8.offset(s, -3), utf8.offset(s, -4), utf8.offset(s, 1, -1), utf8.offset(s, 2, 2)
return pcall(math.random, 1.0), pcall(math.random, "3"), pcall(math.random, 1, 2.0), pcall(math.random, 2^63)
return math.abs("-0"), math.type(math.abs("-0")), pcall(math.abs, "x"), math.max("1", 2), math.type(math.max("1", 2))
return math.floor(2^62), math.ceil(-2^63), math.type(math.ceil(-2^63)), math.floor(-2^63 - 1025), math.type(math.floor(-2^63 - 1025)), math.ceil(2^63 - 512), math.type(math.ceil(2^63 - 512))
local f = load("return select('#', ...), ...")
return f(1, nil, 3)
local f = load("return 'a\0b'")
return #f()
local function mk(n) if n == 0 then return function() return 0 end end local inner = mk(n - 1) return function() return inner() + 1 end end
return mk(100)()
local fs = {}
for i = 1, 3 do for j = 1, 2 do fs[#fs + 1] = function() return i * 10 + j end end end
local r = {}
for _, f in ipairs(fs) do r[#r + 1] = f() end
return table.concat(r, ",")
local function f(...) local a, b, c = ... return a, b, c, table.pack(...).n end
return f(1)
return [==[
]==], [[
]], #[[
a]]
return 1