Throw an error if it cannot find an object after everything is loaded.
The delayed hooking implementation didn't have a flag to say when to stop trying to delay hooks that do not exist.
This commit is contained in:
parent
fa393c4f78
commit
5287ce2569
1 changed files with 15 additions and 7 deletions
|
@ -24,7 +24,9 @@ local HOOK_TYPE_RAW = HOOK_TYPES.rawhook
|
||||||
_registry.origs
|
_registry.origs
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local _delayed = {} -- dont need to attach this to registry.
|
-- dont need to attach this to registry.
|
||||||
|
local _delayed = {}
|
||||||
|
local _delaying_enabled = true
|
||||||
|
|
||||||
-- This metatable will automatically create a table entry if one doesnt exist.
|
-- This metatable will automatically create a table entry if one doesnt exist.
|
||||||
local auto_table_meta = {__index = function(t, k) t[k] = {} return t[k] end }
|
local auto_table_meta = {__index = function(t, k) t[k] = {} return t[k] end }
|
||||||
|
@ -255,12 +257,17 @@ local function generic_hook(self, obj, method, handler, func_name)
|
||||||
-- Check if hook should be delayed.
|
-- Check if hook should be delayed.
|
||||||
local obj, sucess = get_object_from_string(obj) --luacheck: ignore
|
local obj, sucess = get_object_from_string(obj) --luacheck: ignore
|
||||||
if not sucess then
|
if not sucess then
|
||||||
|
if _delaying_enabled then
|
||||||
-- Call this func at a later time, using upvalues.
|
-- Call this func at a later time, using upvalues.
|
||||||
vmf:info("(%s): [%s.%s] needs to be delayed.", func_name, obj, method)
|
vmf:info("(%s): [%s.%s] needs to be delayed.", func_name, obj, method)
|
||||||
table.insert(_delayed, function()
|
table.insert(_delayed, function()
|
||||||
generic_hook(self, obj, method, handler, hook_type)
|
generic_hook(self, obj, method, handler, func_name)
|
||||||
end)
|
end)
|
||||||
return
|
return
|
||||||
|
else
|
||||||
|
self:error("(%s): trying to hook object that doesn't exist: %s", func_name, obj)
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- obj can't be a string for these now.
|
-- obj can't be a string for these now.
|
||||||
|
@ -376,6 +383,7 @@ vmf.hooks_unload = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
vmf.apply_delayed_hooks = function()
|
vmf.apply_delayed_hooks = function()
|
||||||
|
_delaying_enabled = false
|
||||||
if #_delayed > 0 then
|
if #_delayed > 0 then
|
||||||
-- Go through the table in reverse so we don't get any issues removing entries inside the loop
|
-- Go through the table in reverse so we don't get any issues removing entries inside the loop
|
||||||
for i = #_delayed, 1, -1 do
|
for i = #_delayed, 1, -1 do
|
||||||
|
|
Loading…
Add table
Reference in a new issue