aboutsummaryrefslogtreecommitdiff
path: root/system/init.lua
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2025-04-15 13:12:38 +0200
committerGitHub <noreply@github.com>2025-04-15 13:12:38 +0200
commit6d3340004616cdc317bbaca6b279e4cd6d5ee247 (patch)
tree6f680dcdc30efdc2c9929e1510feca27e6dc8c41 /system/init.lua
parent69447022f10d995c22b94759ea872d5dd3905e2a (diff)
downloadluasystem-6d3340004616cdc317bbaca6b279e4cd6d5ee247.tar.gz
luasystem-6d3340004616cdc317bbaca6b279e4cd6d5ee247.tar.bz2
luasystem-6d3340004616cdc317bbaca6b279e4cd6d5ee247.zip
fix(term): autotermrestore was overwriting the metatable (#64)
Diffstat (limited to '')
-rw-r--r--system/init.lua8
1 files changed, 5 insertions, 3 deletions
diff --git a/system/init.lua b/system/init.lua
index e0e5f21..a9f57e9 100644
--- a/system/init.lua
+++ b/system/init.lua
@@ -13,14 +13,16 @@ local system = require 'system.core'
13system.CODEPAGE_UTF8 = 65001 13system.CODEPAGE_UTF8 = 65001
14 14
15do 15do
16 local backup_mt = {} 16 local backup_indicator = {}
17 17
18 --- Returns a backup of terminal settings for stdin/out/err. 18 --- Returns a backup of terminal settings for stdin/out/err.
19 -- Handles terminal/console flags, Windows codepage, and non-block flags on the streams. 19 -- Handles terminal/console flags, Windows codepage, and non-block flags on the streams.
20 -- Backs up terminal/console flags only if a stream is a tty. 20 -- Backs up terminal/console flags only if a stream is a tty.
21 -- @return table with backup of terminal settings 21 -- @return table with backup of terminal settings
22 function system.termbackup() 22 function system.termbackup()
23 local backup = setmetatable({}, backup_mt) 23 local backup = {
24 __type = backup_indicator, -- cannot set a metatable, since autotermrestore uses it for GC
25 }
24 26
25 if system.isatty(io.stdin) then 27 if system.isatty(io.stdin) then
26 backup.console_in = system.getconsoleflags(io.stdin) 28 backup.console_in = system.getconsoleflags(io.stdin)
@@ -51,7 +53,7 @@ do
51 -- @tparam table backup the backup of terminal settings, see `termbackup`. 53 -- @tparam table backup the backup of terminal settings, see `termbackup`.
52 -- @treturn boolean true 54 -- @treturn boolean true
53 function system.termrestore(backup) 55 function system.termrestore(backup)
54 if getmetatable(backup) ~= backup_mt then 56 if type(backup) ~= "table" or backup.__type ~= backup_indicator then
55 error("arg #1 to termrestore, expected backup table, got " .. type(backup), 2) 57 error("arg #1 to termrestore, expected backup table, got " .. type(backup), 2)
56 end 58 end
57 59