diff options
Diffstat (limited to 'liolib.c')
| -rw-r--r-- | liolib.c | 14 |
1 files changed, 13 insertions, 1 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 2.40 2003/04/30 20:15:55 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.41 2003/04/30 20:24:38 roberto Exp roberto $ |
| 3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -457,6 +457,17 @@ static int f_seek (lua_State *L) { | |||
| 457 | } | 457 | } |
| 458 | 458 | ||
| 459 | 459 | ||
| 460 | static int f_setvbuf (lua_State *L) { | ||
| 461 | static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; | ||
| 462 | static const char *const modenames[] = {"no", "full", "line", NULL}; | ||
| 463 | FILE *f = tofile(L, 1); | ||
| 464 | int op = luaL_findstring(luaL_checkstring(L, 2), modenames); | ||
| 465 | luaL_argcheck(L, op != -1, 2, "invalid mode"); | ||
| 466 | return pushresult(L, setvbuf(f, NULL, mode[op], 0) == 0, NULL); | ||
| 467 | } | ||
| 468 | |||
| 469 | |||
| 470 | |||
| 460 | static int io_flush (lua_State *L) { | 471 | static int io_flush (lua_State *L) { |
| 461 | return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); | 472 | return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); |
| 462 | } | 473 | } |
| @@ -488,6 +499,7 @@ static const luaL_reg flib[] = { | |||
| 488 | {"read", f_read}, | 499 | {"read", f_read}, |
| 489 | {"lines", f_lines}, | 500 | {"lines", f_lines}, |
| 490 | {"seek", f_seek}, | 501 | {"seek", f_seek}, |
| 502 | {"setvbuf", f_setvbuf}, | ||
| 491 | {"write", f_write}, | 503 | {"write", f_write}, |
| 492 | {"close", io_close}, | 504 | {"close", io_close}, |
| 493 | {"__gc", io_gc}, | 505 | {"__gc", io_gc}, |
