From 36a6bf6b492888146487d0276cc5991d49bf08e9 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 17 Oct 2024 00:21:42 +0100 Subject: [PATCH] weac.notify: fix __call When you do weac.notify(player_name, "info", "msg"), Lua auto-inserts a `self` table which refers to the main `Notify` table there. This is because `local function call()` is registered via `setmetatable(Notify, ...)`, which auto-inserts `self` as the 1st argument. To this end, this command adds a dummy 1st argument `_self` to capture this extra table to avoid all args being shifted by 1. --- worldeditadditions_core/utils/notify/notify.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/worldeditadditions_core/utils/notify/notify.lua b/worldeditadditions_core/utils/notify/notify.lua index ab18c9c..f844240 100644 --- a/worldeditadditions_core/utils/notify/notify.lua +++ b/worldeditadditions_core/utils/notify/notify.lua @@ -60,11 +60,14 @@ end --- Send a notification of type `ntype` (for metatable). -- (Same as `Notify[ntype](name, message)`) --- @param string name The name of the player to send the notification to. --- @param string ntype The type of notification. --- @param string message The message to send. +-- @param table _self Provided automatically by Lua. You do not need to set this automatically - see example. +-- @param string name The name of the player to send the notification to. +-- @param string ntype The type of notification. +-- @param string message The message to send. -- @return table The Notify instance. -local call = function(name, ntype, message) +-- @example Basic usage +-- worldeditadditions_core.notify(player_name, "info", "All registered commands:\n....") +local call = function(_self, name, ntype, message) if ntype ~= "__call" and not Notify[ntype] then Notify.error(name, "Invalid notification type: " .. ntype) Notify.error(name, "Message: " .. message) @@ -83,7 +86,7 @@ setmetatable(Notify, {__call = call}) -- @param string? colour Optional. The colour of the notification. -- @param boolean? message_coloured Optional. Whether the message should be coloured. -- @return boolean True if all parameters are valid, false otherwise. --- @example Predefined notification types +-- @example Custom notification types -- Notify.custom(name, "custom", "This one is magenta!", "#FF00FF", true) -- Notify.custom(name, "custom", "This one is gold with white text!", "#FFC700") function Notify.custom(name, ntype, message, colour, message_coloured)