From d252e1722953c8ab232a94e7be70a6b606186024 Mon Sep 17 00:00:00 2001 From: FireSiku Date: Sat, 15 Dec 2018 21:43:13 -0500 Subject: [PATCH] hooks: Throw an error if `obj` is nil to avoid clusterfucks. --- vmf/scripts/mods/vmf/modules/core/hooks.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/vmf/scripts/mods/vmf/modules/core/hooks.lua b/vmf/scripts/mods/vmf/modules/core/hooks.lua index 4853bcc..760cfeb 100644 --- a/vmf/scripts/mods/vmf/modules/core/hooks.lua +++ b/vmf/scripts/mods/vmf/modules/core/hooks.lua @@ -250,11 +250,9 @@ end -- mod, table (obj), string (method), function (handler), string (func_name) -- Giving a method string and a hook function (hooking global functions) -- mod, string (method), function (handler), nil, string (func_name) --- Giving a nil value followed by a method stirng and hook function (alternate way for global functions) --- mod, nil, string (method), function (handler), string (func_name) local function generic_hook(mod, obj, method, handler, func_name) - if vmf.check_wrong_argument_type(mod, func_name, "obj", obj, "string", "table", "nil") or + if vmf.check_wrong_argument_type(mod, func_name, "obj", obj, "string", "table") or vmf.check_wrong_argument_type(mod, func_name, "method", method, "string", "function") or vmf.check_wrong_argument_type(mod, func_name, "handler", handler, "function", "nil") then @@ -262,7 +260,7 @@ local function generic_hook(mod, obj, method, handler, func_name) end -- Shift the arguments if needed - if type(method) == "function" then + if not handler then obj, method, handler = nil, obj, method if not method then mod:error("(%s): trying to create hook without giving a method name.", func_name)