diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2020-04-22 01:38:05 +0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2020-04-22 17:30:28 +0300 |
commit | 842505b6a33d0b0e2445568ea42f2adbf3c4eb77 (patch) | |
tree | 87cb50d1f184ee7cb9ffc9d2ce973e3bb5b19fea /src | |
parent | 3e879ffba1b66ede11a038ba46d55475a51e538b (diff) |
Lua 5.4: use __close to close dir if you break the iterator
Diffstat (limited to 'src')
-rw-r--r-- | src/lfs.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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; } |