Tiny refactoring in io.flush
This commit is contained in:
13
liolib.c
13
liolib.c
@@ -732,18 +732,19 @@ static int f_setvbuf (lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int aux_flush (lua_State *L, FILE *f) {
|
||||||
static int io_flush (lua_State *L) {
|
|
||||||
FILE *f = getiofile(L, IO_OUTPUT);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
return luaL_fileresult(L, fflush(f) == 0, NULL);
|
return luaL_fileresult(L, fflush(f) == 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int f_flush (lua_State *L) {
|
static int f_flush (lua_State *L) {
|
||||||
FILE *f = tofile(L);
|
return aux_flush(L, tofile(L));
|
||||||
errno = 0;
|
}
|
||||||
return luaL_fileresult(L, fflush(f) == 0, NULL);
|
|
||||||
|
|
||||||
|
static int io_flush (lua_State *L) {
|
||||||
|
return aux_flush(L, getiofile(L, IO_OUTPUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ collectgarbage()
|
|||||||
|
|
||||||
assert(io.write(' ' .. t .. ' '))
|
assert(io.write(' ' .. t .. ' '))
|
||||||
assert(io.write(';', 'end of file\n'))
|
assert(io.write(';', 'end of file\n'))
|
||||||
f:flush(); io.flush()
|
assert(f:flush()); assert(io.flush())
|
||||||
f:close()
|
f:close()
|
||||||
print('+')
|
print('+')
|
||||||
|
|
||||||
@@ -461,6 +461,23 @@ do -- testing closing file in line iteration
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
do print("testing flush")
|
||||||
|
local f = io.output("/dev/null")
|
||||||
|
assert(f:write("abcd")) -- write to buffer
|
||||||
|
assert(f:flush()) -- write to device
|
||||||
|
assert(f:write("abcd")) -- write to buffer
|
||||||
|
assert(io.flush()) -- write to device
|
||||||
|
assert(f:close())
|
||||||
|
|
||||||
|
local f = io.output("/dev/full")
|
||||||
|
assert(f:write("abcd")) -- write to buffer
|
||||||
|
assert(not f:flush()) -- cannot write to device
|
||||||
|
assert(f:write("abcd")) -- write to buffer
|
||||||
|
assert(not io.flush()) -- cannot write to device
|
||||||
|
assert(f:close())
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- test for multipe arguments in 'lines'
|
-- test for multipe arguments in 'lines'
|
||||||
io.output(file); io.write"0123456789\n":close()
|
io.output(file); io.write"0123456789\n":close()
|
||||||
for a,b in io.lines(file, 1, 1) do
|
for a,b in io.lines(file, 1, 1) do
|
||||||
|
|||||||
Reference in New Issue
Block a user