aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2020-04-21 19:38:05 -0300
committerHisham Muhammad <hisham@gobolinux.org>2020-04-22 11:30:28 -0300
commit842505b6a33d0b0e2445568ea42f2adbf3c4eb77 (patch)
tree87cb50d1f184ee7cb9ffc9d2ce973e3bb5b19fea
parent3e879ffba1b66ede11a038ba46d55475a51e538b (diff)
downloadluafilesystem-842505b6a33d0b0e2445568ea42f2adbf3c4eb77.tar.gz
luafilesystem-842505b6a33d0b0e2445568ea42f2adbf3c4eb77.tar.bz2
luafilesystem-842505b6a33d0b0e2445568ea42f2adbf3c4eb77.zip
Lua 5.4: use __close to close dir if you break the iterator
-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)
725 if (d->dir == NULL) 725 if (d->dir == NULL)
726 luaL_error(L, "cannot open %s: %s", path, strerror(errno)); 726 luaL_error(L, "cannot open %s: %s", path, strerror(errno));
727#endif 727#endif
728#if LUA_VERSION_NUM >= 504
729 lua_pushnil(L);
730 lua_pushvalue(L, -2);
731 return 4;
732#else
728 return 2; 733 return 2;
734#endif
729} 735}
730 736
731 737
@@ -747,6 +753,11 @@ static int dir_create_meta(lua_State * L)
747 lua_setfield(L, -2, "__index"); 753 lua_setfield(L, -2, "__index");
748 lua_pushcfunction(L, dir_close); 754 lua_pushcfunction(L, dir_close);
749 lua_setfield(L, -2, "__gc"); 755 lua_setfield(L, -2, "__gc");
756
757#if LUA_VERSION_NUM >= 504
758 lua_pushcfunction(L, dir_close);
759 lua_setfield(L, -2, "__close");
760#endif
750 return 1; 761 return 1;
751} 762}
752 763