From 1ac6a250244aa86b121783b7f7e20c13ec712c9b Mon Sep 17 00:00:00 2001 From: bi Date: Mon, 28 May 2018 22:12:37 +0300 Subject: [PATCH] Updated the rest of VMF to use new pcall system --- .../mods/vmf/modules/core/commands.lua | 6 ++---- vmf/scripts/mods/vmf/modules/core/events.lua | 6 +----- .../mods/vmf/modules/core/keybindings.lua | 6 ++---- vmf/scripts/mods/vmf/modules/core/network.lua | 20 ++++++++++--------- .../mods/vmf/modules/gui/custom_menus.lua | 6 +++--- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/vmf/scripts/mods/vmf/modules/core/commands.lua b/vmf/scripts/mods/vmf/modules/core/commands.lua index da6db18..bb6897d 100644 --- a/vmf/scripts/mods/vmf/modules/core/commands.lua +++ b/vmf/scripts/mods/vmf/modules/core/commands.lua @@ -139,10 +139,8 @@ vmf.run_command = function(command_name, ...) local command_entry = _COMMANDS[command_name] if command_entry then - local success, error_message = pcall(command_entry.exec_function, ...) - if not success then - command_entry.mod:error("(commands) in command '%s': %s", command_name, tostring(error_message)) - end + local error_prefix = "(commands) " .. tostring(command_name) + vmf.xpcall_no_return_values(command_entry.mod, error_prefix, command_entry.exec_function, ...) else vmf:error("(commands): command '%s' wasn't found.", command_name) -- should never see this end diff --git a/vmf/scripts/mods/vmf/modules/core/events.lua b/vmf/scripts/mods/vmf/modules/core/events.lua index 5350f1e..061fee7 100644 --- a/vmf/scripts/mods/vmf/modules/core/events.lua +++ b/vmf/scripts/mods/vmf/modules/core/events.lua @@ -8,11 +8,7 @@ local _MODS_UNLOADING_ORDER = vmf.mods_unloading_order -- #################################################################################################################### local function run_event(mod, event_name, event, ...) - - local success, error_message = pcall(event, ...) - if not success then - mod:error("(mod.%s): %s", event_name, error_message) - end + vmf.xpcall_no_return_values(mod, "(event) " .. event_name, event, ...) end -- #################################################################################################################### diff --git a/vmf/scripts/mods/vmf/modules/core/keybindings.lua b/vmf/scripts/mods/vmf/modules/core/keybindings.lua index 1ed091d..90959b2 100644 --- a/vmf/scripts/mods/vmf/modules/core/keybindings.lua +++ b/vmf/scripts/mods/vmf/modules/core/keybindings.lua @@ -134,10 +134,8 @@ vmf.check_pressed_keybinds = function() local action_exists, action_function = pcall(function() return mod[binding_info[2]] end) if action_exists then - local success, error_message = pcall(action_function) - if not success then - mod:error("(keybindings)(mod.%s): %s", tostring(binding_info[2]), tostring(error_message)) - end + local error_prefix = "(keybindings) " .. tostring(binding_info[2]) + vmf.xpcall_no_return_values(mod, error_prefix, action_function) else mod:error("(keybindings): function '%s' wasn't found.", tostring(binding_info[2])) end diff --git a/vmf/scripts/mods/vmf/modules/core/network.lua b/vmf/scripts/mods/vmf/modules/core/network.lua index ed6c9fb..19c36b3 100644 --- a/vmf/scripts/mods/vmf/modules/core/network.lua +++ b/vmf/scripts/mods/vmf/modules/core/network.lua @@ -150,13 +150,13 @@ end local function send_rpc_vmf_data_local(mod_name, rpc_name, ...) - if get_mod(mod_name):is_enabled() then + local mod = get_mod(mod_name) + + if mod:is_enabled() then network_debug("data", "local", nil, mod_name, rpc_name, {...}) - local success, error_message = pcall(_RPC_CALLBACKS[mod_name][rpc_name], Network.peer_id(), ...) - if not success then - get_mod(mod_name):error("(local rpc) in rpc '%s': %s", tostring(rpc_name), tostring(error_message)) - end + local error_prefix = "(local rpc) " .. tostring(rpc_name) + vmf.xpcall_no_return_values(mod, error_prefix, _RPC_CALLBACKS[mod_name][rpc_name], Network.peer_id(), ...) end end @@ -277,10 +277,12 @@ vmf:hook("ChatManager.rpc_chat_message", function(func, self, sender, channel_id network_debug("data", "received", sender, mod_name, rpc_name, localization_param) -- can be error in both callback_function() and deserialize_data() - local success, error_message = pcall(function() _RPC_CALLBACKS[mod_name][rpc_name](sender, deserialize_data(localization_param)) end) - if not success then - get_mod(mod_name):error("(network) in rpc function '%s': %s", rpc_name, tostring(error_message)) - end + local error_prefix = "(network) " .. tostring(rpc_name) + vmf.xpcall_no_return_values( + get_mod(mod_name), + error_prefix, + function() _RPC_CALLBACKS[mod_name][rpc_name](sender, deserialize_data(localization_param)) end + ) end end end diff --git a/vmf/scripts/mods/vmf/modules/gui/custom_menus.lua b/vmf/scripts/mods/vmf/modules/gui/custom_menus.lua index dc87902..5d5d06b 100644 --- a/vmf/scripts/mods/vmf/modules/gui/custom_menus.lua +++ b/vmf/scripts/mods/vmf/modules/gui/custom_menus.lua @@ -169,14 +169,14 @@ vmf.close_opened_custom_menus = function() if views_settings[current_view] then ingame_ui:handle_transition("exit_menu") - --if current_view ~= "vmf_options_view" then if ingame_ui.views[current_view].destroy and get_mod(views_settings[ingame_ui.current_view].mod_name) then - get_mod(views_settings[ingame_ui.current_view].mod_name):pcall(ingame_ui.views[current_view].destroy) + local mod = get_mod(views_settings[current_view].mod_name) + local destroy_method = ingame_ui.views[current_view].destroy + vmf.xpcall_no_return_values(mod, "(custom menus) destroy view", destroy_method) end ingame_ui.views[current_view] = nil - --end end end end