| 224 | |
| 225 | |
| 226 | static int io_open (lua_State *L) { |
| 227 | const char *filename = luaL_checkstring(L, 1); |
| 228 | const char *mode = luaL_optstring(L, 2, "r"); |
| 229 | LStream *p = newfile(L); |
| 230 | const char *md = mode; /* to traverse/check mode */ |
| 231 | luaL_argcheck(L, lua_checkmode(md), 2, "invalid mode"); |
| 232 | p->f = fopen(filename, mode); |
| 233 | return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; |
| 234 | } |
| 235 | |
| 236 | |
| 237 | /* |
nothing calls this directly
no test coverage detected