diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib_io.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/lib_io.c b/src/lib_io.c index 037aa28e..a502dd52 100644 --- a/src/lib_io.c +++ b/src/lib_io.c | |||
| @@ -278,6 +278,15 @@ static int io_file_iter(lua_State *L) | |||
| 278 | return n; | 278 | return n; |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | static int io_file_lines(lua_State *L) | ||
| 282 | { | ||
| 283 | int n = (int)(L->top - L->base); | ||
| 284 | if (n > LJ_MAX_UPVAL) | ||
| 285 | lj_err_caller(L, LJ_ERR_UNPACK); | ||
| 286 | lua_pushcclosure(L, io_file_iter, n); | ||
| 287 | return 1; | ||
| 288 | } | ||
| 289 | |||
| 281 | /* -- I/O file methods ---------------------------------------------------- */ | 290 | /* -- I/O file methods ---------------------------------------------------- */ |
| 282 | 291 | ||
| 283 | #define LJLIB_MODULE_io_method | 292 | #define LJLIB_MODULE_io_method |
| @@ -361,8 +370,7 @@ LJLIB_CF(io_method_setvbuf) | |||
| 361 | LJLIB_CF(io_method_lines) | 370 | LJLIB_CF(io_method_lines) |
| 362 | { | 371 | { |
| 363 | io_tofile(L); | 372 | io_tofile(L); |
| 364 | lua_pushcclosure(L, io_file_iter, (int)(L->top - L->base)); | 373 | return io_file_lines(L); |
| 365 | return 1; | ||
| 366 | } | 374 | } |
| 367 | 375 | ||
| 368 | LJLIB_CF(io_method___gc) | 376 | LJLIB_CF(io_method___gc) |
| @@ -492,8 +500,7 @@ LJLIB_CF(io_lines) | |||
| 492 | } else { /* io.lines() iterates over stdin. */ | 500 | } else { /* io.lines() iterates over stdin. */ |
| 493 | setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_INPUT)); | 501 | setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_INPUT)); |
| 494 | } | 502 | } |
| 495 | lua_pushcclosure(L, io_file_iter, (int)(L->top - L->base)); | 503 | return io_file_lines(L); |
| 496 | return 1; | ||
| 497 | } | 504 | } |
| 498 | 505 | ||
| 499 | LJLIB_CF(io_type) | 506 | LJLIB_CF(io_type) |
