Bring Lua to 5.4.6. (#1214)

This essentially re-does the work of #875 on top of master.

This is what I did to check that Cosmo's Lua extensions still worked:

```
$ build/bootstrap/make MODE=aarch64 o/aarch64/third_party/lua/lua
$ ape o/aarch64/third_party/lua/lua
>: 10
10
>: 010
8
>: 0b10
2
>: string.byte("\e")
27
>: "Hello, %s" % {"world"}
Hello, world
>: "*" * 3
***
```

`luaL_traceback2` was used to show the stack trace with parameter
values; it's used in `LuaCallWithTrace`, which is used in Redbean to run
Lua code. You should be able to see the extended stack trace by running
something like this: `redbean -e "function a(b)c()end a(2)"` (with
"params" indicating the extended stack trace):

```
stack traceback:
 [string "function a(b)c()end a(2)"]:1: in function 'a', params: b = 2;
 [string "function a(b)c()end a(2)"]:1: in main chunk
```
@pkulchenko confirmed that I get the expected result with the updated
code.

This is what I did to check that Lua itself still worked:

```
$ cd third_party/lua/test/
$ ape ../../../o/aarch64/third_party/lua/lua all.lua
```

There's one test failure, in `files.lua`:

```
***** FILE 'files.lua'*****
testing i/o
../../../o/aarch64/third_party/lua/lua: files.lua:84: assertion failed!
stack traceback:
[C]: in function 'assert'
files.lua:84: in main chunk
(...tail calls...)
all.lua:195: in main chunk
[C]: in ?
.>>> closing state <<<
```

That isn't a result of these changes; the same test is failing in
master.

The failure is here:

```lua
if not _port then   -- invalid seek
  local status, msg, code = io.stdin:seek("set", 1000)
  assert(not status and type(msg) == "string" and type(code) == "number")
end
```

The test expects a seek to offset 1,000 on stdin to fail — but it
doesn't. `status` ends up being the new offset rather than `nil`.

If I comment out that one test, the remaining tests succeed.
This commit is contained in:
Michael Lenaghan 2024-06-15 20:13:08 -04:00 committed by GitHub
parent 3a599bfbe1
commit 0dbf01bf1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
90 changed files with 2741 additions and 1376 deletions

View file

@ -9,6 +9,16 @@ local function checkerror (msg, f, ...)
end
local function check (t, na, nh)
if not T then return end
local a, h = T.querytab(t)
if a ~= na or h ~= nh then
print(na, nh, a, h)
assert(nil)
end
end
local a = {}
-- make sure table has lots of space in hash part
@ -20,6 +30,25 @@ for i=1,100 do
assert(#a == i)
end
do -- rehash moving elements from array to hash
local a = {}
for i = 1, 100 do a[i] = i end
check(a, 128, 0)
for i = 5, 95 do a[i] = nil end
check(a, 128, 0)
a.x = 1 -- force a re-hash
check(a, 4, 8)
for i = 1, 4 do assert(a[i] == i) end
for i = 5, 95 do assert(a[i] == nil) end
for i = 96, 100 do assert(a[i] == i) end
assert(a.x == 1)
end
-- testing ipairs
local x = 0
for k,v in ipairs{10,20,30;x=12} do
@ -43,6 +72,14 @@ assert(i == 4)
assert(type(ipairs{}) == 'function' and ipairs{} == ipairs{})
do -- overflow (must wrap-around)
local f = ipairs{}
local k, v = f({[math.mininteger] = 10}, math.maxinteger)
assert(k == math.mininteger and v == 10)
k, v = f({[math.mininteger] = 10}, k)
assert(k == nil)
end
if not T then
(Message or print)
('\n >>> testC not active: skipping tests for table sizes <<<\n')
@ -57,15 +94,6 @@ local function mp2 (n) -- minimum power of 2 >= n
end
local function check (t, na, nh)
local a, h = T.querytab(t)
if a ~= na or h ~= nh then
print(na, nh, a, h)
assert(nil)
end
end
-- testing C library sizes
do
local s = 0
@ -161,7 +189,7 @@ end
-- size tests for vararg
lim = 35
function foo (n, ...)
local function foo (n, ...)
local arg = {...}
check(arg, n, 0)
assert(select('#', ...) == n)
@ -499,6 +527,15 @@ do -- testing table library with metamethods
end
do -- testing overflow in table.insert (must wrap-around)
local t = setmetatable({},
{__len = function () return math.maxinteger end})
table.insert(t, 20)
local k, v = next(t)
assert(k == math.mininteger and v == 20)
end
if not T then
(Message or print)
('\n >>> testC not active: skipping tests for table library on non-tables <<<\n')
@ -764,4 +801,25 @@ for k,v in ipairs(a) do
end
assert(i == a.n)
-- testing yield inside __pairs
do
local t = setmetatable({10, 20, 30}, {__pairs = function (t)
local inc = coroutine.yield()
return function (t, i)
if i > 1 then return i - inc, t[i - inc] else return nil end
end, t, #t + 1
end})
local res = {}
local co = coroutine.wrap(function ()
for i,p in pairs(t) do res[#res + 1] = p end
end)
co() -- start coroutine
co(1) -- continue after yield
assert(res[1] == 30 and res[2] == 20 and res[3] == 10 and #res == 3)
end
print"OK"