From 09df371d99f8cd311212dccfc5ab60d5731b4cef Mon Sep 17 00:00:00 2001 From: Gnome Ann <> Date: Sun, 12 Dec 2021 11:30:04 -0500 Subject: [PATCH] Handle nested wrapped functions in bridge.lua properly --- bridge.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bridge.lua b/bridge.lua index e4017f16..a8e12874 100644 --- a/bridge.lua +++ b/bridge.lua @@ -78,6 +78,8 @@ return function(_python, _bridged) -- metatables prior to executing the function body --========================================================================== + local wrapped = false + ---@class Metatables local metatables = {} local type_map = { @@ -111,10 +113,18 @@ return function(_python, _bridged) function metawrapper.__newindex(t, k, v) if type(v) == "function" then return rawset(t, k, function(...) - metatables:overwrite() - metatables_original:restore() + local _needs_unwrap = false + if not wrapped then + metatables:overwrite() + metatables_original:restore() + _needs_unwrap = true + wrapped = true + end local r = {v(...)} - metatables:restore() + if _needs_unwrap then + metatables:restore() + wrapped = false + end return table.unpack(r) end) else