mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(imports/callback): response varargs
Trying to have scrt compatible responses gets weird when using msgpack.
This commit is contained in:
@@ -43,15 +43,16 @@ local function triggerServerCallback(_, event, delay, cb, ...)
|
||||
---@type promise | false
|
||||
local promise = not cb and promise.new()
|
||||
|
||||
events[key] = function(response)
|
||||
events[key] = function(response, ...)
|
||||
response = { response, ... }
|
||||
events[key] = nil
|
||||
|
||||
if promise then
|
||||
return promise:resolve(response and { msgpack.unpack(response) } or {})
|
||||
return promise:resolve(response)
|
||||
end
|
||||
|
||||
if cb and response then
|
||||
cb(msgpack.unpack(response))
|
||||
if cb then
|
||||
cb(table.unpack(response))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -81,7 +82,7 @@ local function callbackResponse(success, result, ...)
|
||||
return false
|
||||
end
|
||||
|
||||
return msgpack.pack(result, ...)
|
||||
return result, ...
|
||||
end
|
||||
|
||||
local pcall = pcall
|
||||
|
||||
@@ -24,15 +24,16 @@ local function triggerClientCallback(_, event, playerId, cb, ...)
|
||||
---@type promise | false
|
||||
local promise = not cb and promise.new()
|
||||
|
||||
events[key] = function(response)
|
||||
events[key] = function(response, ...)
|
||||
response = { response, ... }
|
||||
events[key] = nil
|
||||
|
||||
if promise then
|
||||
return promise:resolve(response and { msgpack.unpack(response) } or {})
|
||||
return promise:resolve(response)
|
||||
end
|
||||
|
||||
if cb and response then
|
||||
cb(msgpack.unpack(response))
|
||||
if cb then
|
||||
cb(table.unpack(response))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -62,7 +63,7 @@ local function callbackResponse(success, result, ...)
|
||||
return false
|
||||
end
|
||||
|
||||
return msgpack.pack(result, ...)
|
||||
return result, ...
|
||||
end
|
||||
|
||||
local pcall = pcall
|
||||
|
||||
Reference in New Issue
Block a user