File hook fixes. Still need to fix rehooks
This commit is contained in:
parent
c77af55020
commit
e97c394006
3 changed files with 17 additions and 11 deletions
|
@ -401,14 +401,13 @@ function DMFMod:hook_file(obj_str, method_str, handler)
|
||||||
_hooks_by_file[obj_str] = _hooks_by_file[obj_str] or {}
|
_hooks_by_file[obj_str] = _hooks_by_file[obj_str] or {}
|
||||||
|
|
||||||
local hook_create_func = function(this_filepath, this_index)
|
local hook_create_func = function(this_filepath, this_index)
|
||||||
local dynamic_obj =
|
local dynamic_obj = self:get_require_store(this_filepath)[this_index]
|
||||||
"dmf:get_require_store(\"" .. this_filepath .. "\")[" .. tostring(this_index) .. "]"
|
|
||||||
return generic_hook(self, dynamic_obj, method_str, handler, "hook")
|
return generic_hook(self, dynamic_obj, method_str, handler, "hook")
|
||||||
end
|
end
|
||||||
table.insert(_hooks_by_file[obj_str], hook_create_func)
|
table.insert(_hooks_by_file[obj_str], hook_create_func)
|
||||||
|
|
||||||
-- Add the new hook to every instance of the file
|
-- Add the new hook to every instance of the file
|
||||||
local all_file_instances = dmf:get_require_store(obj_str)
|
local all_file_instances = self:get_require_store(obj_str)
|
||||||
if all_file_instances then
|
if all_file_instances then
|
||||||
for i, item in ipairs(all_file_instances) do
|
for i, item in ipairs(all_file_instances) do
|
||||||
if item then
|
if item then
|
||||||
|
@ -468,11 +467,9 @@ dmf.apply_delayed_hooks = function(status, state)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
dmf.apply_hooks_to_file = function(filepath, store_index)
|
dmf.apply_hooks_to_file = function(require_store, filepath, store_index)
|
||||||
local all_file_instances = dmf:get_require_store(filepath)
|
|
||||||
local file_instance = all_file_instances and all_file_instances[store_index]
|
|
||||||
|
|
||||||
local all_file_hooks = _hooks_by_file[filepath]
|
local all_file_hooks = _hooks_by_file[filepath]
|
||||||
|
local file_instance = require_store and require_store[store_index]
|
||||||
|
|
||||||
if all_file_hooks and file_instance then
|
if all_file_hooks and file_instance then
|
||||||
for _, hook_create_func in ipairs(all_file_hooks) do
|
for _, hook_create_func in ipairs(all_file_hooks) do
|
||||||
|
|
|
@ -39,7 +39,8 @@ local _notification_types = {
|
||||||
|
|
||||||
local function add_chat_notification(message, notification_type, sound_event, replay_to_chat_on_error)
|
local function add_chat_notification(message, notification_type, sound_event, replay_to_chat_on_error)
|
||||||
if Managers.event then
|
if Managers.event then
|
||||||
Managers.event:trigger("event_add_notification_message",
|
Managers.event:trigger(
|
||||||
|
"event_add_notification_message",
|
||||||
_notification_types[notification_type] and notification_type or "default",
|
_notification_types[notification_type] and notification_type or "default",
|
||||||
message or "",
|
message or "",
|
||||||
nil,
|
nil,
|
||||||
|
|
|
@ -62,12 +62,20 @@ end
|
||||||
-- ##### Hooks #########################################################################################################
|
-- ##### Hooks #########################################################################################################
|
||||||
-- #####################################################################################################################
|
-- #####################################################################################################################
|
||||||
|
|
||||||
-- Handles the swap to io for registered files
|
-- Handles the swap to io for registered files and the application of file hooks
|
||||||
dmf:hook(_G, "require", function (func, path, ...)
|
dmf:hook(_G, "require", function (func, path, ...)
|
||||||
if _io_requires[path] then
|
if _io_requires[path] then
|
||||||
return dmf:dofile(path)
|
return dmf:dofile(path)
|
||||||
else
|
else
|
||||||
return func(path, ...)
|
local result = func(path, ...)
|
||||||
|
|
||||||
|
-- Apply any file hooks to the newly-required file
|
||||||
|
local require_store = get_require_store(path)
|
||||||
|
if require_store then
|
||||||
|
dmf.apply_hooks_to_file(require_store, path, #require_store)
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue