| 12112 | |
| 12113 | |
| 12114 | static int g_iofile (lua_State *L, int f, const char *mode) { |
| 12115 | if (!lua_isnoneornil(L, 1)) { |
| 12116 | const char *filename = lua_tostring(L, 1); |
| 12117 | if (filename) { |
| 12118 | FILE **pf = newfile(L); |
| 12119 | *pf = fopen(filename, mode); |
| 12120 | if (*pf == NULL) |
| 12121 | fileerror(L, 1, filename); |
| 12122 | } |
| 12123 | else { |
| 12124 | tofile(L); /* check that it's a valid file handle */ |
| 12125 | lua_pushvalue(L, 1); |
| 12126 | } |
| 12127 | lua_rawseti(L, LUA_ENVIRONINDEX, f); |
| 12128 | } |
| 12129 | /* return current value */ |
| 12130 | lua_rawgeti(L, LUA_ENVIRONINDEX, f); |
| 12131 | return 1; |
| 12132 | } |
| 12133 | |
| 12134 | |
| 12135 | static int io_input (lua_State *L) { |
no test coverage detected