次の例を検討してください。
function Process()
local Container=NewContainer()
Container:On(EventType.Add,function()
Container:DoSomething()
end)
-- Does not Garbage Collect
end
luabridge では、 asの寿命を延ばすfunction()
asを保存します。LuaRef
Container
RefCountedObjectPtr
これは、機能する弱いテーブルを使用するために使用する回避策ですが、見栄えが悪いです。
function Process()
local Container=NewContainer()
local ParamsTable={ Container=Container }
setmetatable(ParamsTable, { __mode = 'k' })
Container:On(EventType.Add,function()
ParamsTable.Container:DoSomething()
end)
-- Garbage Collects fine
end
LuaRef
これに似た機能を持つ方法はありますか?それとも別の回避策がありますか?