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