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