From 842505b6a33d0b0e2445568ea42f2adbf3c4eb77 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 21 Apr 2020 19:38:05 -0300 Subject: Lua 5.4: use __close to close dir if you break the iterator --- src/lfs.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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; } -- cgit v1.2.3-55-g6feb