Tiny refactoring in io.flush

This commit is contained in:
Roberto Ierusalimschy
2025-04-03 12:56:52 -03:00
parent 3f4f28010a
commit 620f49a7aa
2 changed files with 25 additions and 7 deletions

View File

@@ -732,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));
}