Stop storing ref to e2funcs(fixes nil access after e2 refresh)

This commit is contained in:
DerelictDrone 2024-08-21 23:28:05 -05:00
parent 5912bd344c
commit 4edec3a164

View File

@ -113,8 +113,19 @@ end
delayed(1,function()
local E2Mode = E2Helper:RegisterMode("E2")
if E2Mode then
E2Mode.Descriptions = E2Helper.Descriptions
E2Mode.Items = wire_expression2_funcs -- May be worth replacing this with a metatable to fetch the table from global.
local E2ModeMetatable = {
__index = function(self,key)
if key == "Items" then return wire_expression2_funcs end
if key == "Descriptions" then return E2Helper.Descriptions end
return nil
end
}
E2Mode.Items = nil
E2Mode.Descriptions = nil
-- The metatable is needed because storing a ref to wire_expression2_funcs
-- and then causing e2 to reload (like changing extensions) doesn't update the ref
-- or something like that, it causes e2helper to access nil values.
setmetatable(E2Mode,E2ModeMetatable)
E2Mode.ModeSetup = function(E2HelperPanel)
E2HelperPanel.FunctionColumn:SetName("Function")
E2HelperPanel.FunctionColumn:SetWidth(126)