Override the `__close` metamethod of `FILE*` objects

This enables the use of a Lua 5.4 feature where you can have Lua
auto-close a file when exiting a block. For example:

```
do
    local f <close> = kobold.get_config_file()
end
```

If we exit from the `do` block under any circumstances, including via an
error or return statement, the `FILE*` `f` automatically closes right
before that happens.
This commit is contained in:
Gnome Ann 2021-12-31 16:56:44 -05:00
parent 796c71b7f7
commit a580f18a14
1 changed files with 1 additions and 0 deletions

View File

@ -279,6 +279,7 @@ return function(_python, _bridged)
end
end
debug.getmetatable(io.stdout).__index.close = _new_close(io.stdout.close)
debug.getmetatable(io.stdout).__close = _new_close(io.stdout.close)
---@param filename string
---@return boolean