mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-06-27 07:32:56 +00:00
Make http.websocket call synchronous in bios.lua
I thought I'd done this already, but it's possible it got lost during a rebase.
This commit is contained in:
parent
ba9cfa3764
commit
4e9034f910
@ -737,6 +737,28 @@ if http then
|
|||||||
if url == _url then return ok, err end
|
if url == _url then return ok, err end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local nativeWebsocket = http.websocket
|
||||||
|
http.websocketAsync = nativeWebsocket
|
||||||
|
http.websocket = function( _url, _headers )
|
||||||
|
if type( _url ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( _url ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
if _headers ~= nil and type( _headers ) ~= "table" then
|
||||||
|
error( "bad argument #2 (expected table, got " .. type( _headers ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
local ok, err = nativeWebsocket( _url, _headers )
|
||||||
|
if not ok then return ok, err end
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local event, url, param = os.pullEvent( )
|
||||||
|
if event == "websocket_success" and url == _url then
|
||||||
|
return param
|
||||||
|
elseif event == "websocket_failure" and url == _url then
|
||||||
|
return false, param
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Install the lua part of the FS api
|
-- Install the lua part of the FS api
|
||||||
|
Loading…
x
Reference in New Issue
Block a user