diff options
-rw-r--r-- | src/lfs.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -197,15 +197,23 @@ static int get_dir (lua_State *L) { | |||
197 | ** Check if the given element on the stack is a file and returns it. | 197 | ** Check if the given element on the stack is a file and returns it. |
198 | */ | 198 | */ |
199 | static FILE *check_file (lua_State *L, int idx, const char *funcname) { | 199 | static FILE *check_file (lua_State *L, int idx, const char *funcname) { |
200 | #if LUA_VERSION_NUM == 501 | ||
200 | FILE **fh = (FILE **)luaL_checkudata (L, idx, "FILE*"); | 201 | FILE **fh = (FILE **)luaL_checkudata (L, idx, "FILE*"); |
201 | if (fh == NULL) { | 202 | if (*fh == NULL) { |
202 | luaL_error (L, "%s: not a file", funcname); | ||
203 | return 0; | ||
204 | } else if (*fh == NULL) { | ||
205 | luaL_error (L, "%s: closed file", funcname); | 203 | luaL_error (L, "%s: closed file", funcname); |
206 | return 0; | 204 | return 0; |
207 | } else | 205 | } else |
208 | return *fh; | 206 | return *fh; |
207 | #elif LUA_VERSION_NUM >= 502 && LUA_VERSION_NUM <= 503 | ||
208 | luaL_Stream *fh = (luaL_Stream *)luaL_checkudata (L, idx, "FILE*"); | ||
209 | if (fh->closef == 0 || fh->f == NULL) { | ||
210 | luaL_error (L, "%s: closed file", funcname); | ||
211 | return 0; | ||
212 | } else | ||
213 | return fh->f; | ||
214 | #else | ||
215 | #error unsupported Lua version | ||
216 | #endif | ||
209 | } | 217 | } |
210 | 218 | ||
211 | 219 | ||