Не работает asyncHttpRequest

ZoomDev

Известный
Автор темы
38
16
Версия MoonLoader
.025-beta
Взял код с https://www.blast.hk/threads/20532/
Lua:
function httpRequest(method, request, args, handler) -- lua-requests
    -- start polling task
    if not copas.running then
        copas.running = true
        lua_thread.create(function()
            wait(0)
            while not copas.finished() do
                local ok, err = copas.step(0)
                if ok == nil then error(err) end
                wait(0)
            end
            copas.running = false
        end)
    end
    -- do request
    if handler then
        return copas.addthread(function(m, r, a, h)
            copas.setErrorHandler(function(err) h(nil, err) end)
            h(requests.request(m, r, a))
        end, method, request, args, handler)
    else
        local results
        local thread = copas.addthread(function(m, r, a)
            copas.setErrorHandler(function(err) results = {nil, err} end)
            results = table.pack(requests.request(m, r, a))
        end, method, request, args)
        while coroutine.status(thread) ~= 'dead' do wait(0) end
        return table.unpack(results) -- Строка, выдающая ошибка
    end
end

Вызов функции:
Lua:
print(httpRequest("GET", url .. "messages/-1"))

Но выдаёт ошибку attempt to call field 'unpack' (a nil value)
 
Последнее редактирование:

Sadow

Известный
1,437
585
Взял код с https://www.blast.hk/threads/20532/
Lua:
function httpRequest(method, request, args, handler) -- lua-requests
    -- start polling task
    if not copas.running then
        copas.running = true
        lua_thread.create(function()
            wait(0)
            while not copas.finished() do
                local ok, err = copas.step(0)
                if ok == nil then error(err) end
                wait(0)
            end
            copas.running = false
        end)
    end
    -- do request
    if handler then
        return copas.addthread(function(m, r, a, h)
            copas.setErrorHandler(function(err) h(nil, err) end)
            h(requests.request(m, r, a))
        end, method, request, args, handler)
    else
        local results
        local thread = copas.addthread(function(m, r, a)
            copas.setErrorHandler(function(err) results = {nil, err} end)
            results = table.pack(requests.request(m, r, a))
        end, method, request, args)
        while coroutine.status(thread) ~= 'dead' do wait(0) end
        return table.unpack(results) -- Строка, выдающая ошибка
    end
end

Вызов функции:
Lua:
print(httpRequest(url .. "messages/-1"))

Но выдаёт ошибку attempt to call field 'unpack' (a nil value)
Библиотеки подключал?
Lua:
local copas = require 'copas'
local http = require 'copas.http'