mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(callback): warn if callback function is nil/false
Between the headache of people misusing callbacks and people complaining about third-party resources that misused them, I would rather just shut them up. I'll just deprecate this crap at some point anyway.
This commit is contained in:
@@ -68,9 +68,14 @@ end
|
|||||||
---@overload fun(event: string, delay: number | false, cb: function, ...)
|
---@overload fun(event: string, delay: number | false, cb: function, ...)
|
||||||
lib.callback = setmetatable({}, {
|
lib.callback = setmetatable({}, {
|
||||||
__call = function(_, event, delay, cb, ...)
|
__call = function(_, event, delay, cb, ...)
|
||||||
local cbType = type(cb)
|
if not cb then
|
||||||
|
warn(("callback event '%s' does not have a function to callback to and will instead await\nuse lib.callback.await or a regular event to remove this warning")
|
||||||
|
:format(event))
|
||||||
|
else
|
||||||
|
local cbType = type(cb)
|
||||||
|
|
||||||
assert(cbType == 'function', ("expected argument 3 to have type 'function' (received %s)"):format(cbType))
|
assert(cbType == 'function', ("expected argument 3 to have type 'function' (received %s)"):format(cbType))
|
||||||
|
end
|
||||||
|
|
||||||
return triggerServerCallback(_, event, delay, cb, ...)
|
return triggerServerCallback(_, event, delay, cb, ...)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -51,9 +51,14 @@ end
|
|||||||
---@overload fun(event: string, playerId: number, cb: function, ...)
|
---@overload fun(event: string, playerId: number, cb: function, ...)
|
||||||
lib.callback = setmetatable({}, {
|
lib.callback = setmetatable({}, {
|
||||||
__call = function(_, event, playerId, cb, ...)
|
__call = function(_, event, playerId, cb, ...)
|
||||||
local cbType = type(cb)
|
if not cb then
|
||||||
|
warn(("callback event '%s' does not have a function to callback to and will instead await\nuse lib.callback.await or a regular event to remove this warning")
|
||||||
|
:format(event))
|
||||||
|
else
|
||||||
|
local cbType = type(cb)
|
||||||
|
|
||||||
assert(cbType == 'function', ("expected argument 3 to have type 'function' (received %s)"):format(cbType))
|
assert(cbType == 'function', ("expected argument 3 to have type 'function' (received %s)"):format(cbType))
|
||||||
|
end
|
||||||
|
|
||||||
return triggerClientCallback(_, event, playerId, cb, ...)
|
return triggerClientCallback(_, event, playerId, cb, ...)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user