diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-06-20 10:10:04 +0200 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2024-06-20 10:20:33 +0200 |
commit | b87e6d6d762ee823e81dd7a8984f330eb4018fd8 (patch) | |
tree | b9a92dff6462abd5859c3c76f19748fad5d6c025 | |
parent | 906044cb31569d7681ccf9d161f98fe3bd409277 (diff) | |
download | luasystem-b87e6d6d762ee823e81dd7a8984f330eb4018fd8.zip |
simplify the __gc check
-rw-r--r-- | system/init.lua | 16 |
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 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 |