summaryrefslogtreecommitdiff
path: root/src/lib_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib_io.c')
-rw-r--r--src/lib_io.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/lib_io.c b/src/lib_io.c
index 01623258..aefe4213 100644
--- a/src/lib_io.c
+++ b/src/lib_io.c
@@ -523,8 +523,11 @@ static void io_fenv_new(lua_State *L, int narr, lua_CFunction cls)
523 523
524LUALIB_API int luaopen_io(lua_State *L) 524LUALIB_API int luaopen_io(lua_State *L)
525{ 525{
526 LJ_LIB_REG_(L, NULL, io_method); 526 lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);
527 lua_setfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); 527 if (tvisnil(L->top-1)) {
528 LJ_LIB_REG_(L, NULL, io_method);
529 lua_setfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);
530 }
528 io_fenv_new(L, 0, lj_cf_io_pipe_close); /* top-3 */ 531 io_fenv_new(L, 0, lj_cf_io_pipe_close); /* top-3 */
529 io_fenv_new(L, 2, lj_cf_io_file_close); /* top-2 */ 532 io_fenv_new(L, 2, lj_cf_io_file_close); /* top-2 */
530 LJ_LIB_REG(L, io); 533 LJ_LIB_REG(L, io);
@@ -532,7 +535,7 @@ LUALIB_API int luaopen_io(lua_State *L)
532 io_std_new(L, stdin, IO_INPUT, "stdin"); 535 io_std_new(L, stdin, IO_INPUT, "stdin");
533 io_std_new(L, stdout, IO_OUTPUT, "stdout"); 536 io_std_new(L, stdout, IO_OUTPUT, "stdout");
534 io_std_new(L, stderr, 0, "stderr"); 537 io_std_new(L, stderr, 0, "stderr");
535 lua_pop(L, 1); 538 L->top--;
536 return 1; 539 return 1;
537} 540}
538 541