Merge branch 'master' into v2.1

This commit is contained in:
Mike Pall 2024-08-19 17:33:23 +02:00
commit fb5e1c9f0d

View File

@ -101,6 +101,7 @@ LUALIB_API int luaL_loadfilex(lua_State *L, const char *filename,
FileReaderCtx ctx; FileReaderCtx ctx;
int status; int status;
const char *chunkname; const char *chunkname;
int err = 0;
if (filename) { if (filename) {
chunkname = lua_pushfstring(L, "@%s", filename); chunkname = lua_pushfstring(L, "@%s", filename);
ctx.fp = fopen(filename, "rb"); ctx.fp = fopen(filename, "rb");
@ -114,17 +115,16 @@ LUALIB_API int luaL_loadfilex(lua_State *L, const char *filename,
chunkname = "=stdin"; chunkname = "=stdin";
} }
status = lua_loadx(L, reader_file, &ctx, chunkname, mode); status = lua_loadx(L, reader_file, &ctx, chunkname, mode);
if (ferror(ctx.fp)) { if (ferror(ctx.fp)) err = errno;
L->top -= filename ? 2 : 1;
lua_pushfstring(L, "cannot read %s: %s", chunkname+1, strerror(errno));
if (filename)
fclose(ctx.fp);
return LUA_ERRFILE;
}
if (filename) { if (filename) {
fclose(ctx.fp);
L->top--; L->top--;
copyTV(L, L->top-1, L->top); copyTV(L, L->top-1, L->top);
fclose(ctx.fp); }
if (err) {
L->top--;
lua_pushfstring(L, "cannot read %s: %s", chunkname+1, strerror(err));
return LUA_ERRFILE;
} }
return status; return status;
} }