| 198 | |
| 199 | |
| 200 | static int g_iofile (lua_State *L, int f, const char *mode) { |
| 201 | if (!lua_isnoneornil(L, 1)) { |
| 202 | const char *filename = lua_tostring(L, 1); |
| 203 | if (filename) { |
| 204 | FILE **pf = newfile(L); |
| 205 | *pf = fopen(filename, mode); |
| 206 | if (*pf == NULL) |
| 207 | fileerror(L, 1, filename); |
| 208 | } |
| 209 | else { |
| 210 | tofile(L); /* check that it's a valid file handle */ |
| 211 | lua_pushvalue(L, 1); |
| 212 | } |
| 213 | lua_rawseti(L, LUA_ENVIRONINDEX, f); |
| 214 | } |
| 215 | /* return current value */ |
| 216 | lua_rawgeti(L, LUA_ENVIRONINDEX, f); |
| 217 | return 1; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | static int io_input (lua_State *L) { |
no test coverage detected