From 2d20c3d3069a7c21b7dbaba17742768d2e7dd4e2 Mon Sep 17 00:00:00 2001 From: Antoine Cellerier Date: Sat, 11 Feb 2012 12:22:24 +0100 Subject: [PATCH] Fix host destructor call. --- share/lua/intf/modules/host.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/share/lua/intf/modules/host.lua b/share/lua/intf/modules/host.lua index aeadc02c78..6b31037c07 100644 --- a/share/lua/intf/modules/host.lua +++ b/share/lua/intf/modules/host.lua @@ -319,7 +319,7 @@ function host() local function destructor( h ) for _,client in pairs(clients) do - client:send("Shutting down.") + --client:send("Cleaning up.") if client.type == client_type.net or client.type == client_type.telnet then if client.wfd ~= client.rfd then @@ -336,6 +336,14 @@ function host() end end + if setfenv then + -- We're running Lua 5.1 + -- See http://lua-users.org/wiki/HiddenFeatures for more info. + local proxy = newproxy(true) + getmetatable(proxy).__gc = destructor + destructor = proxy + end + -- the instance local h = setmetatable( { -- data @@ -348,7 +356,7 @@ function host() broadcast = _broadcast, }, { -- metatable - __gc = destructor, + __gc = destructor, -- Should work in Lua 5.2 without the new proxytrick as __gc is also called on tables (needs to be tested) __metatable = "", }) return h -- 2.39.2