Skip to content

Commit 2909cb5

Browse files
committed
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.
1 parent d147e70 commit 2909cb5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

imports/callback/client.lua

+7-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ end
6868
---@overload fun(event: string, delay: number | false, cb: function, ...)
6969
lib.callback = setmetatable({}, {
7070
__call = function(_, event, delay, cb, ...)
71-
local cbType = type(cb)
71+
if not cb then
72+
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")
73+
:format(event))
74+
else
75+
local cbType = type(cb)
7276

73-
assert(cbType == 'function', ("expected argument 3 to have type 'function' (received %s)"):format(cbType))
77+
assert(cbType == 'function', ("expected argument 3 to have type 'function' (received %s)"):format(cbType))
78+
end
7479

7580
return triggerServerCallback(_, event, delay, cb, ...)
7681
end

imports/callback/server.lua

+7-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ end
5151
---@overload fun(event: string, playerId: number, cb: function, ...)
5252
lib.callback = setmetatable({}, {
5353
__call = function(_, event, playerId, cb, ...)
54-
local cbType = type(cb)
54+
if not cb then
55+
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")
56+
:format(event))
57+
else
58+
local cbType = type(cb)
5559

56-
assert(cbType == 'function', ("expected argument 3 to have type 'function' (received %s)"):format(cbType))
60+
assert(cbType == 'function', ("expected argument 3 to have type 'function' (received %s)"):format(cbType))
61+
end
5762

5863
return triggerClientCallback(_, event, playerId, cb, ...)
5964
end

0 commit comments

Comments
 (0)