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 8836d052..2aa83474 100644 --- a/src/lib_io.c +++ b/src/lib_io.c | |||
| @@ -273,6 +273,15 @@ static int io_file_iter(lua_State *L) | |||
| 273 | return n; | 273 | return n; |
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | static int io_file_lines(lua_State *L) | ||
| 277 | { | ||
| 278 | int n = (int)(L->top - L->base); | ||
| 279 | if (n > LJ_MAX_UPVAL) | ||
| 280 | lj_err_caller(L, LJ_ERR_UNPACK); | ||
| 281 | lua_pushcclosure(L, io_file_iter, n); | ||
| 282 | return 1; | ||
| 283 | } | ||
| 284 | |||
| 276 | /* -- I/O file methods ---------------------------------------------------- */ | 285 | /* -- I/O file methods ---------------------------------------------------- */ |
| 277 | 286 | ||
| 278 | #define LJLIB_MODULE_io_method | 287 | #define LJLIB_MODULE_io_method |
| @@ -356,8 +365,7 @@ LJLIB_CF(io_method_setvbuf) | |||
| 356 | LJLIB_CF(io_method_lines) | 365 | LJLIB_CF(io_method_lines) |
| 357 | { | 366 | { |
| 358 | io_tofile(L); | 367 | io_tofile(L); |
| 359 | lua_pushcclosure(L, io_file_iter, (int)(L->top - L->base)); | 368 | return io_file_lines(L); |
| 360 | return 1; | ||
| 361 | } | 369 | } |
| 362 | 370 | ||
| 363 | LJLIB_CF(io_method___gc) | 371 | LJLIB_CF(io_method___gc) |
| @@ -487,8 +495,7 @@ LJLIB_CF(io_lines) | |||
| 487 | } else { /* io.lines() iterates over stdin. */ | 495 | } else { /* io.lines() iterates over stdin. */ |
| 488 | setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_INPUT)); | 496 | setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_INPUT)); |
| 489 | } | 497 | } |
| 490 | lua_pushcclosure(L, io_file_iter, (int)(L->top - L->base)); | 498 | return io_file_lines(L); |
| 491 | return 1; | ||
| 492 | } | 499 | } |
| 493 | 500 | ||
| 494 | LJLIB_CF(io_type) | 501 | LJLIB_CF(io_type) |
