Handle nested wrapped functions in bridge.lua properly

This commit is contained in:
Gnome Ann 2021-12-12 11:30:04 -05:00
parent 00eb125ad0
commit 09df371d99
1 changed files with 13 additions and 3 deletions

View File

@ -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(...)
local _needs_unwrap = false
if not wrapped then
metatables:overwrite()
metatables_original:restore()
_needs_unwrap = true
wrapped = true
end
local r = {v(...)}
if _needs_unwrap then
metatables:restore()
wrapped = false
end
return table.unpack(r)
end)
else