Skip to content

Commit 0dbf01b

Browse files
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.
1 parent 3a599bf commit 0dbf01b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2740
-1375
lines changed

third_party/lua/README.cosmo

Lines changed: 127 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ PROVENANCE
99

1010
https://github.com/lua/lua/
1111

12-
commit e7803f7dbcdc966ab1f9db143424ee811ab1a398
12+
commit 6443185167c77adcc8552a3fee7edab7895db1a9
1313
Author: Roberto Ierusalimschy <[email protected]>
14-
Date: Wed Mar 3 09:44:20 2021 -0300
14+
Date: May 2, 2023 at 3:44 PM EDT
1515

16-
New release number (5.4.3)
16+
New release number (5.4.6)
1717

1818
luac.c needed to be sourced from:
19-
https://www.lua.org/ftp/lua-5.4.3.tar.gz
19+
https://www.lua.org/ftp/lua-5.4.6.tar.gz
2020

2121
LOCAL MODIFICATIONS
2222

@@ -31,10 +31,130 @@ LOCAL MODIFICATIONS
3131
character. It may be used for teletypewriter control like having
3232
bold text, which can be encoded elegantly as `\e[1mHELLO\e[0m`.
3333

34-
Added luaL_traceback2() for function parameters in traceback.
34+
Added Python-like printf modulus operator for strings, e.g.:
35+
`"Hello, %s!" % {"world"}`.
36+
37+
Added Python-like printf multiply operator for strings, e.g.:
38+
`"Hello, world! " * 3`.
3539

36-
Added Python-like printf modulus operator for strings.
40+
Added `unix` module that exposes the low-level System Five system
41+
call interface, e.g.: `require("unix"); print(unix.getcwd())`.
3742

38-
Added Python-like printf multiply operator for strings.
43+
Added luaL_traceback2() for function parameters in traceback.
3944

4045
Fixed a buffer overflow in os.tmpname
46+
47+
NOTES
48+
49+
If you'd like to update Cosmo's Lua to the latest version, here
50+
are some things that might be helpful to know.
51+
52+
Cosmo's Lua adds ~20 or so files (e.g., `luacallwithtrace.c`,
53+
`luaencodejsondata.c`, `luaencodeluadata.c`, etc.) to the
54+
directory. In other words, a bunch of Cosmo's files don't
55+
have any Lua counterpart.
56+
57+
Some of those files (e.g., `lunix.c`, `lunix.h`) implement
58+
functionality that's available within the `lua` that Cosmo builds;
59+
most, though, implement functionality that's (currently?) only
60+
available within `redbean`. In other words, not everything can be
61+
tested using `lua`; some things need to be tested using `redbean`.
62+
63+
Some of Lua's files were renamed. For example, `lua.c` was renamed
64+
to `lua.main.c`, and `luac.c` (which is only available in Lua's
65+
distributions, and not in Lua's Github repo) was renamed to
66+
`luac.main.c`. `ljumptab.h` was renamed to `ljumptab.inc`, and
67+
`lopnames.h` was renamed to `lopnames.inc`. In other words, you'll
68+
need to take some kind of action in order to properly diff all of
69+
Lua's files.
70+
71+
Lua's `.h` files had the comment headers that look like this
72+
removed:
73+
74+
/*
75+
** $Id: lua.h $
76+
** Lua - A Scripting Language
77+
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
78+
** See Copyright Notice at the end of this file
79+
*/
80+
81+
Lua's `.c` files *replaced* those comment headers with a Cosmo
82+
emacs/vim header followed by a Lua copyright declaration.
83+
84+
The `.c` files also added a `__static_yoink("lua_notice");`
85+
right after the `#include`s.
86+
87+
Some of Lua's tests have been modified to accommodate Cosmo's
88+
changes. (And some of Lua's tests have been commented out
89+
due to Cosmo's changes.)
90+
91+
Five of Lua's test files intentionally contain ISO-8859-1 (rather
92+
than UTF-8) characters:
93+
94+
* test/db.lua
95+
* test/files.lua
96+
* test/pm.lua
97+
* test/sort.lua
98+
* test/strings.lua
99+
100+
If you edit those files as if they were UTF-8-encoded you'll
101+
corrupt the ISO-8859-1 characters and cause certain tests to fail.
102+
(Some of the tests count bytes, so you can't just fix the problem
103+
by converting the files — you also have to change various expected
104+
results.)
105+
106+
The modifications listed way up above are really only the
107+
*user-visible* modifications. There are many that aren't
108+
user-visible. For example, `_longjmp` was replaced with
109+
`gclongjmp`, and `abort` was replaced, ultimately, with a
110+
call to `_Exit`.
111+
112+
To update Cosmo's Lua, you'll need to diff the latest Lua against
113+
the previous Lua, and Cosmo's Lua against the latest Lua. As you
114+
do that, you'll be trying to figure out both what Lua changed
115+
*and* what Cosmo changed; you'll be trying to add Lua's changes
116+
without accidentally removing Cosmo's changes.
117+
118+
It's tricky!
119+
120+
We've started to try to make that process a bit easier by tagging
121+
Cosmo's changes with `[jart]`. For example, one side of the diff
122+
might (now) show:
123+
124+
#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
125+
126+
while the other side might (now) show:
127+
128+
#define LUAI_THROW(L,c) gclongjmp((c)->b, 1) // [jart]
129+
130+
The presence of the `[jart]` tag makes it easy to see that the
131+
Cosmo change was intentional.
132+
133+
Be aware that not all changes have been tagged!
134+
135+
There are *other* things we've done that are *also* meant to make
136+
diffing easier — though the intention is less obvious.
137+
138+
For example, Cosmo moved the `enum` of opcodes from `ltm.h` to
139+
`tms.h`. Originally nothing at all was left behind in `ltm.h`.
140+
Because of that, you'd see an `enum` in Lua that seemed to be
141+
missing in Cosmo's Lua — as though the `enum` had recently been
142+
added to Lua, and now needed to be added to Cosmo! To make the
143+
intention of Cosmo's change more obvious, we added a tombstone
144+
of sorts to `ltm.h`:
145+
146+
/*
147+
* WARNING: if you change the order of this enumeration,
148+
* grep "ORDER TM" and "ORDER OP"
149+
*/
150+
// [jart] moved to tms.h
151+
152+
The comment just above the tag comes from Lua; it's the comment
153+
above Lua's original `enum`. *The presence of the comment in both
154+
Lua and Cosmo helps diff tools "resync" at that point.* That in
155+
turn makes it easier to see Cosmo's change, and to see that it was
156+
intentional.
157+
158+
The more things like that we do — the easier we can make it to
159+
quickly and correctly read diffs — the easier we'll make it to
160+
keep Cosmo's Lua in sync with the latest Lua.

0 commit comments

Comments
 (0)