Skip to content

Commit 9fc08b4

Browse files
committed
Detect reload and clear state
1 parent 0b2b25f commit 9fc08b4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

gooey/gooey.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,17 @@ end
4242
-- @return Instance for the node
4343
local function instance(id, instances)
4444
local key = to_key(id)
45-
instances[key] = instances[key] or {}
46-
return instances[key]
45+
local instance = instances[key]
46+
-- detect a reload (unload and load cycle) and start with an
47+
-- empty instance
48+
-- if the script instance has changed then we're certain that
49+
-- it's reloaded
50+
local script_instance = _G.__dm_script_instance__
51+
if instance and instance.__script ~= script_instance then
52+
instances[key] = nil
53+
end
54+
instances[key] = instances[key] or { __script = script_instance, data = {} }
55+
return instances[key].data
4756
end
4857

4958
--- Convenience function to acquire input focus

0 commit comments

Comments
 (0)