From b87e6d6d762ee823e81dd7a8984f330eb4018fd8 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Thu, 20 Jun 2024 10:10:04 +0200 Subject: simplify the __gc check --- system/init.lua | 16 +++------------- 1 file 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 local add_gc_method do - -- feature detection; __GC meta-method, not available in all Lua versions - local has_gc = false - local tt = setmetatable({}, { -- luacheck: ignore - __gc = function() has_gc = true end - }) - - -- clear table and run GC to trigger - tt = nil - collectgarbage() - collectgarbage() - + -- __gc meta-method is not available in all Lua versions + local has_gc = not newproxy or false -- `__gc` was added when `newproxy` was removed if has_gc then -- use default GC mechanism since it is available @@ -120,8 +111,7 @@ do -- autotermrestore return nil, "global terminal backup was already set up" end global_backup = system.termbackup() - add_gc_method(global_backup, function(self) - system.termrestore(self) end) + add_gc_method(global_backup, function(self) pcall(system.termrestore, self) end) return true end -- cgit v1.2.3