Lua 5.5.0 Release (#2119)

* Lua 5.5 beta

* lua 5.5.0 release
This commit is contained in:
云风
2025-12-23 10:19:09 +08:00
committed by GitHub
parent 28e8087029
commit 406f3a7437
66 changed files with 6125 additions and 3857 deletions

View File

@@ -21,8 +21,7 @@
#include "lauxlib.h"
#include "lualib.h"
#include "llimits.h"
/*
@@ -115,7 +114,7 @@ static int l_checkmode (const char *mode) {
#if !defined(l_fseek) /* { */
#if defined(LUA_USE_POSIX) /* { */
#if defined(LUA_USE_POSIX) || defined(LUA_USE_OFF_T) /* { */
#include <sys/types.h>
@@ -444,7 +443,7 @@ static int nextc (RN *rn) {
return 0; /* fail */
}
else {
rn->buff[rn->n++] = rn->c; /* save current char */
rn->buff[rn->n++] = cast_char(rn->c); /* save current char */
rn->c = l_getc(rn->f); /* read next one */
return 1;
}
@@ -525,15 +524,15 @@ static int read_line (lua_State *L, FILE *f, int chop) {
luaL_buffinit(L, &b);
do { /* may need to read several chunks to get whole line */
char *buff = luaL_prepbuffer(&b); /* preallocate buffer space */
int i = 0;
unsigned i = 0;
l_lockfile(f); /* no memory errors can happen inside the lock */
while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')
buff[i++] = c; /* read up to end of line or buffer limit */
buff[i++] = cast_char(c); /* read up to end of line or buffer limit */
l_unlockfile(f);
luaL_addsize(&b, i);
} while (c != EOF && c != '\n'); /* repeat until end of line */
if (!chop && c == '\n') /* want a newline and have one? */
luaL_addchar(&b, c); /* add ending newline to result */
luaL_addchar(&b, '\n'); /* add ending newline to result */
luaL_pushresult(&b); /* close buffer */
/* return ok if read something (either a newline or something else) */
return (c == '\n' || lua_rawlen(L, -1) > 0);
@@ -663,28 +662,28 @@ static int io_readline (lua_State *L) {
static int g_write (lua_State *L, FILE *f, int arg) {
int nargs = lua_gettop(L) - arg;
int status = 1;
size_t totalbytes = 0; /* total number of bytes written */
errno = 0;
for (; nargs--; arg++) {
if (lua_type(L, arg) == LUA_TNUMBER) {
/* optimization: could be done exactly as for strings */
int len = lua_isinteger(L, arg)
? fprintf(f, LUA_INTEGER_FMT,
(LUAI_UACINT)lua_tointeger(L, arg))
: fprintf(f, LUA_NUMBER_FMT,
(LUAI_UACNUMBER)lua_tonumber(L, arg));
status = status && (len > 0);
for (; nargs--; arg++) { /* for each argument */
char buff[LUA_N2SBUFFSZ];
const char *s;
size_t numbytes; /* bytes written in one call to 'fwrite' */
size_t len = lua_numbertocstring(L, arg, buff); /* try as a number */
if (len > 0) { /* did conversion work (value was a number)? */
s = buff;
len--;
}
else {
size_t l;
const char *s = luaL_checklstring(L, arg, &l);
status = status && (fwrite(s, sizeof(char), l, f) == l);
else /* must be a string */
s = luaL_checklstring(L, arg, &len);
numbytes = fwrite(s, sizeof(char), len, f);
totalbytes += numbytes;
if (numbytes < len) { /* write error? */
int n = luaL_fileresult(L, 0, NULL);
lua_pushinteger(L, cast_st2S(totalbytes));
return n + 1; /* return fail, error msg., error code, and counter */
}
}
if (l_likely(status))
return 1; /* file handle already on stack top */
else
return luaL_fileresult(L, status, NULL);
return 1; /* no errors; file handle already on stack top */
}
@@ -733,18 +732,19 @@ static int f_setvbuf (lua_State *L) {
}
static int io_flush (lua_State *L) {
FILE *f = getiofile(L, IO_OUTPUT);
static int aux_flush (lua_State *L, FILE *f) {
errno = 0;
return luaL_fileresult(L, fflush(f) == 0, NULL);
}
static int f_flush (lua_State *L) {
FILE *f = tofile(L);
errno = 0;
return luaL_fileresult(L, fflush(f) == 0, NULL);
return aux_flush(L, tofile(L));
}
static int io_flush (lua_State *L) {
return aux_flush(L, getiofile(L, IO_OUTPUT));
}