Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keplerproject/luafilesystem.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2020-04-22 01:38:05 +0300
committerHisham Muhammad <hisham@gobolinux.org>2020-04-22 17:30:28 +0300
commit842505b6a33d0b0e2445568ea42f2adbf3c4eb77 (patch)
tree87cb50d1f184ee7cb9ffc9d2ce973e3bb5b19fea /src
parent3e879ffba1b66ede11a038ba46d55475a51e538b (diff)
Lua 5.4: use __close to close dir if you break the iterator
Diffstat (limited to 'src')
-rw-r--r--src/lfs.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/lfs.c b/src/lfs.c
index 17700fa..99a35bb 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -725,7 +725,13 @@ static int dir_iter_factory(lua_State * L)
if (d->dir == NULL)
luaL_error(L, "cannot open %s: %s", path, strerror(errno));
#endif
+#if LUA_VERSION_NUM >= 504
+ lua_pushnil(L);
+ lua_pushvalue(L, -2);
+ return 4;
+#else
return 2;
+#endif
}
@@ -747,6 +753,11 @@ static int dir_create_meta(lua_State * L)
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, dir_close);
lua_setfield(L, -2, "__gc");
+
+#if LUA_VERSION_NUM >= 504
+ lua_pushcfunction(L, dir_close);
+ lua_setfield(L, -2, "__close");
+#endif
return 1;
}