aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lfs.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/lfs.c b/src/lfs.c
index 020267d..8b4cfd2 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -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*/
199static FILE *check_file (lua_State *L, int idx, const char *funcname) { 199static 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