aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2024-06-20 10:10:04 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2024-06-20 10:20:33 +0200
commitb87e6d6d762ee823e81dd7a8984f330eb4018fd8 (patch)
treeb9a92dff6462abd5859c3c76f19748fad5d6c025
parent906044cb31569d7681ccf9d161f98fe3bd409277 (diff)
downloadluasystem-b87e6d6d762ee823e81dd7a8984f330eb4018fd8.tar.gz
luasystem-b87e6d6d762ee823e81dd7a8984f330eb4018fd8.tar.bz2
luasystem-b87e6d6d762ee823e81dd7a8984f330eb4018fd8.zip
simplify the __gc check
-rw-r--r--system/init.lua16
1 files changed, 3 insertions, 13 deletions
diff --git a/system/init.lua b/system/init.lua
index 926370c..e99d0d4 100644
--- a/system/init.lua
+++ b/system/init.lua
@@ -78,17 +78,8 @@ do -- autotermrestore
78 78
79 79
80 local add_gc_method do 80 local add_gc_method do
81 -- feature detection; __GC meta-method, not available in all Lua versions 81 -- __gc meta-method is not available in all Lua versions
82 local has_gc = false 82 local has_gc = not newproxy or false -- `__gc` was added when `newproxy` was removed
83 local tt = setmetatable({}, { -- luacheck: ignore
84 __gc = function() has_gc = true end
85 })
86
87 -- clear table and run GC to trigger
88 tt = nil
89 collectgarbage()
90 collectgarbage()
91
92 83
93 if has_gc then 84 if has_gc then
94 -- use default GC mechanism since it is available 85 -- use default GC mechanism since it is available
@@ -120,8 +111,7 @@ do -- autotermrestore
120 return nil, "global terminal backup was already set up" 111 return nil, "global terminal backup was already set up"
121 end 112 end
122 global_backup = system.termbackup() 113 global_backup = system.termbackup()
123 add_gc_method(global_backup, function(self) 114 add_gc_method(global_backup, function(self) pcall(system.termrestore, self) end)
124 system.termrestore(self) end)
125 return true 115 return true
126 end 116 end
127 117