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