Files
aceVM/AceVM/components/internet.lua
2025-09-29 00:03:57 -04:00

28 lines
707 B
Lua

local internet = {}
local function wrap_request(_url, ...)
local ok, err = http.request(...)
if ok then
while true do
local event, param1, param2, param3 = coroutine.yield()
if event == "http_success" and param1 == _url then
return param2
elseif event == "http_failure" and param1 == _url then
return nil, param2, param3
end
end
end
return nil, err
end
local function get(_url)
if type(_url) ~= "string" then
error("URL must be a string")
end
return wrap_request(_url, _url)
end
function internet.get(url) return get(url).readAll() end
newComponent("internet", internet)