update lua 5.5.1

This commit is contained in:
Cloud Wu
2026-07-19 18:22:02 +08:00
parent f19d1605b4
commit 5027096d53
34 changed files with 312 additions and 213 deletions

View File

@@ -340,9 +340,11 @@ static int load_aux (lua_State *L, int status, int envidx) {
static const char *getMode (lua_State *L, int idx) {
const char *mode = luaL_optstring(L, idx, "bt");
if (strchr(mode, 'B') != NULL) /* Lua code cannot use fixed buffers */
const char *mode = luaL_optstring(L, idx, NULL);
if (mode != NULL && strchr(mode, 'B') != NULL) {
/* Lua code cannot use fixed buffers */
luaL_argerror(L, idx, "invalid mode");
}
return mode;
}
@@ -364,33 +366,24 @@ static int luaB_loadfile (lua_State *L) {
/*
** reserved slot, above all arguments, to hold a copy of the returned
** string to avoid it being collected while parsed. 'load' has four
** optional arguments (chunk, source name, mode, and environment).
*/
#define RESERVEDSLOT 5
/*
** Reader for generic 'load' function: 'lua_load' uses the
** stack for internal stuff, so the reader cannot change the
** stack top. Instead, it keeps its resulting string in a
** reserved slot inside the stack.
** Reader for generic 'load' function.
*/
static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
(void)(ud); /* not used */
int *firstcall = cast(int *, ud);
luaL_checkstack(L, 2, "too many nested functions");
if (*firstcall)
*firstcall = 0;
else
lua_pop(L, 1); /* remove previous result */
lua_pushvalue(L, 1); /* get function */
lua_call(L, 0, 1); /* call it */
if (lua_isnil(L, -1)) {
lua_pop(L, 1); /* pop result */
*size = 0;
return NULL;
}
else if (l_unlikely(!lua_isstring(L, -1)))
luaL_error(L, "reader function must return a string");
lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
return lua_tolstring(L, RESERVEDSLOT, size);
return lua_tolstring(L, -1, size);
}
@@ -405,10 +398,10 @@ static int luaB_load (lua_State *L) {
status = luaL_loadbufferx(L, s, l, chunkname, mode);
}
else { /* loading from a reader function */
int firstcall = 1; /* userdata for generic_reader */
const char *chunkname = luaL_optstring(L, 2, "=(load)");
luaL_checktype(L, 1, LUA_TFUNCTION);
lua_settop(L, RESERVEDSLOT); /* create reserved slot */
status = lua_load(L, generic_reader, NULL, chunkname, mode);
status = lua_load(L, generic_reader, &firstcall, chunkname, mode);
}
return load_aux(L, status, env);
}
@@ -425,7 +418,7 @@ static int dofilecont (lua_State *L, int d1, lua_KContext d2) {
static int luaB_dofile (lua_State *L) {
const char *fname = luaL_optstring(L, 1, NULL);
lua_settop(L, 1);
if (l_unlikely(luaL_loadfile(L, fname) != LUA_OK))
if (l_unlikely(luaL_loadfilex(L, fname, "bt") != LUA_OK))
return lua_error(L);
lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);
return dofilecont(L, 0, 0);