| 540 | |
| 541 | |
| 542 | LUALIB_API int luaopen_io (lua_State *L) { |
| 543 | createmeta(L); |
| 544 | /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ |
| 545 | newfenv(L, io_fclose); |
| 546 | lua_replace(L, LUA_ENVIRONINDEX); |
| 547 | /* open library */ |
| 548 | luaL_register(L, LUA_IOLIBNAME, iolib); |
| 549 | /* create (and set) default files */ |
| 550 | newfenv(L, io_noclose); /* close function for default files */ |
| 551 | createstdfile(L, stdin, IO_INPUT, "stdin"); |
| 552 | createstdfile(L, stdout, IO_OUTPUT, "stdout"); |
| 553 | createstdfile(L, stderr, 0, "stderr"); |
| 554 | lua_pop(L, 1); /* pop environment for default files */ |
| 555 | lua_getfield(L, -1, "popen"); |
| 556 | newfenv(L, io_pclose); /* create environment for 'popen' */ |
| 557 | lua_setfenv(L, -2); /* set fenv for 'popen' */ |
| 558 | lua_pop(L, 1); /* pop 'popen' */ |
| 559 | return 1; |
| 560 | } |
| 561 |
nothing calls this directly
no test coverage detected