Merge pull request #3 from danreeves/fix-delayed-class-hooks

Fix delayed class hooks
This commit is contained in:
Aussiemon 2023-01-13 02:42:32 -07:00 committed by GitHub
commit 2925e4a9f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -499,11 +499,17 @@ end
-- #################################################################################################################### -- ####################################################################################################################
-- If class() is called on an object we've delayed for, re-run delayed hooks -- If class() is called on an object we've delayed for, re-run delayed hooks
dmf:hook_safe(_G, "class", function(class_name) dmf:hook(_G, "class", function(func, class_name, ...)
local class_object = func(class_name, ...)
if _delayed_obj_names[class_name] then if _delayed_obj_names[class_name] then
dmf:info("%s is now available for previously-delayed hooks.", class_name) dmf:info("%s is now available for previously-delayed hooks.", class_name)
dmf.apply_delayed_hooks()
-- Methods aren't defined yet, so we need to wait for the instance creation to apply delayed hooks
dmf:hook_safe(class_object, "new", function ()
dmf.apply_delayed_hooks()
_delayed_obj_names[class_name] = nil _delayed_obj_names[class_name] = nil
dmf:hook_disable(class_object, "new")
end)
end end
return class_object
end) end)