Update k.lua and others
This commit is contained in:
@@ -18,13 +18,16 @@ end
|
||||
|
||||
local function findID(url)
|
||||
local found = gfind(url, idPatt)
|
||||
if found then
|
||||
return tonumber(found[#found]:sub(found[#found]:find("%d+")))
|
||||
end
|
||||
if not found then return nil end
|
||||
return tonumber(found[#found]:sub(found[#found]:find("%d+")))
|
||||
end
|
||||
|
||||
local function newID()
|
||||
return #callbackRegistry + 1
|
||||
for i = 1, math.huge do
|
||||
if not callbackRegistry[i] then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function trimID(url)
|
||||
@@ -36,8 +39,8 @@ end
|
||||
function request(callback, url, headers, postData)
|
||||
local id = newID()
|
||||
local newUrl = url .. "#R" .. id
|
||||
http.request(newUrl, postData, headers)
|
||||
callbackRegistry[id] = callback
|
||||
http.request(newUrl, postData, headers)
|
||||
end
|
||||
|
||||
function init(jua)
|
||||
@@ -46,7 +49,7 @@ function init(jua)
|
||||
local id = findID(url)
|
||||
if id and callbackRegistry[id] then
|
||||
callbackRegistry[id](true, trimID(url), handle)
|
||||
table.remove(callbackRegistry, id)
|
||||
callbackRegistry[id] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -54,7 +57,7 @@ function init(jua)
|
||||
local id = findID(url)
|
||||
if id and callbackRegistry[id] then
|
||||
callbackRegistry[id](false, trimID(url), handle)
|
||||
table.remove(callbackRegistry, id)
|
||||
callbackRegistry[id] = nil
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -62,4 +65,4 @@ end
|
||||
return {
|
||||
request = request,
|
||||
init = init
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user