mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-22 02:53:06 +00:00
Lua 5.4: use __close to close dir if you break the iterator
This commit is contained in:
11
src/lfs.c
11
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user