Updated the rest of VMF to use new pcall system

This commit is contained in:
bi 2018-05-28 22:12:37 +03:00
parent a7e88ef128
commit 1ac6a25024
5 changed files with 19 additions and 25 deletions

View file

@ -139,10 +139,8 @@ vmf.run_command = function(command_name, ...)
local command_entry = _COMMANDS[command_name] local command_entry = _COMMANDS[command_name]
if command_entry then if command_entry then
local success, error_message = pcall(command_entry.exec_function, ...) local error_prefix = "(commands) " .. tostring(command_name)
if not success then vmf.xpcall_no_return_values(command_entry.mod, error_prefix, command_entry.exec_function, ...)
command_entry.mod:error("(commands) in command '%s': %s", command_name, tostring(error_message))
end
else else
vmf:error("(commands): command '%s' wasn't found.", command_name) -- should never see this vmf:error("(commands): command '%s' wasn't found.", command_name) -- should never see this
end end

View file

@ -8,11 +8,7 @@ local _MODS_UNLOADING_ORDER = vmf.mods_unloading_order
-- #################################################################################################################### -- ####################################################################################################################
local function run_event(mod, event_name, event, ...) local function run_event(mod, event_name, event, ...)
vmf.xpcall_no_return_values(mod, "(event) " .. event_name, event, ...)
local success, error_message = pcall(event, ...)
if not success then
mod:error("(mod.%s): %s", event_name, error_message)
end
end end
-- #################################################################################################################### -- ####################################################################################################################

View file

@ -134,10 +134,8 @@ vmf.check_pressed_keybinds = function()
local action_exists, action_function = pcall(function() return mod[binding_info[2]] end) local action_exists, action_function = pcall(function() return mod[binding_info[2]] end)
if action_exists then if action_exists then
local success, error_message = pcall(action_function) local error_prefix = "(keybindings) " .. tostring(binding_info[2])
if not success then vmf.xpcall_no_return_values(mod, error_prefix, action_function)
mod:error("(keybindings)(mod.%s): %s", tostring(binding_info[2]), tostring(error_message))
end
else else
mod:error("(keybindings): function '%s' wasn't found.", tostring(binding_info[2])) mod:error("(keybindings): function '%s' wasn't found.", tostring(binding_info[2]))
end end

View file

@ -150,13 +150,13 @@ end
local function send_rpc_vmf_data_local(mod_name, rpc_name, ...) 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, {...}) network_debug("data", "local", nil, mod_name, rpc_name, {...})
local success, error_message = pcall(_RPC_CALLBACKS[mod_name][rpc_name], Network.peer_id(), ...) local error_prefix = "(local rpc) " .. tostring(rpc_name)
if not success then vmf.xpcall_no_return_values(mod, error_prefix, _RPC_CALLBACKS[mod_name][rpc_name], Network.peer_id(), ...)
get_mod(mod_name):error("(local rpc) in rpc '%s': %s", tostring(rpc_name), tostring(error_message))
end
end end
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) network_debug("data", "received", sender, mod_name, rpc_name, localization_param)
-- can be error in both callback_function() and deserialize_data() -- 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) local error_prefix = "(network) " .. tostring(rpc_name)
if not success then vmf.xpcall_no_return_values(
get_mod(mod_name):error("(network) in rpc function '%s': %s", rpc_name, tostring(error_message)) get_mod(mod_name),
end error_prefix,
function() _RPC_CALLBACKS[mod_name][rpc_name](sender, deserialize_data(localization_param)) end
)
end end
end end
end end

View file

@ -169,14 +169,14 @@ vmf.close_opened_custom_menus = function()
if views_settings[current_view] then if views_settings[current_view] then
ingame_ui:handle_transition("exit_menu") 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 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 end
ingame_ui.views[current_view] = nil ingame_ui.views[current_view] = nil
--end
end end
end end
end end