mirror of
https://github.com/TangentFoxy/itchy.git
synced 2024-11-25 15:24:20 +00:00
fixed typos, v3 ready
This commit is contained in:
parent
90056afcbc
commit
93aa79ae17
55
itchy.lua
55
itchy.lua
@ -8,22 +8,28 @@ thread = function(...)
|
|||||||
thread, timer = _obj_0.thread, _obj_0.timer
|
thread, timer = _obj_0.thread, _obj_0.timer
|
||||||
end
|
end
|
||||||
local http = require("socket.http")
|
local http = require("socket.http")
|
||||||
local _, libcurl = pcall(function()
|
local ok, libcurl = pcall(function()
|
||||||
return require("luajit-request")
|
return require("luajit-request")
|
||||||
end)
|
end)
|
||||||
if not (libcurl) then
|
if not (ok) then
|
||||||
_, libcurl = pcall(function()
|
ok, libcurl = pcall(function()
|
||||||
return require("lib.luajit-request")
|
return require("lib.luajit-request")
|
||||||
end)
|
end)
|
||||||
|
if not (ok) then
|
||||||
|
libcurl = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local request
|
local request
|
||||||
request = function(data)
|
request = function(data)
|
||||||
local result = { }
|
local result = { }
|
||||||
if not (libcurl) then
|
if not (libcurl) then
|
||||||
if data.luajit_request then
|
if data.luajit_request then
|
||||||
_, libcurl = pcall(function()
|
ok, libcurl = pcall(function()
|
||||||
return require(data.luajit_request)
|
return require(data.luajit_request)
|
||||||
end)
|
end)
|
||||||
|
if not (ok) then
|
||||||
|
libcurl = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if libcurl then
|
if libcurl then
|
||||||
@ -58,7 +64,6 @@ thread = function(...)
|
|||||||
send:push(result)
|
send:push(result)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local ok
|
|
||||||
ok, result = request(data)
|
ok, result = request(data)
|
||||||
if not (ok) then
|
if not (ok) then
|
||||||
send:push(result)
|
send:push(result)
|
||||||
@ -134,3 +139,43 @@ end
|
|||||||
if not (love.graphics or love.window) then
|
if not (love.graphics or love.window) then
|
||||||
return thread(...)
|
return thread(...)
|
||||||
end
|
end
|
||||||
|
local thread_data = love.filesystem.newFileData(string.dump(thread), "itchy version checker")
|
||||||
|
local counter = 1
|
||||||
|
local configs, results = { }, { }
|
||||||
|
local default_data
|
||||||
|
local itchy = {
|
||||||
|
check_version = function(self, data)
|
||||||
|
if not (default_data) then
|
||||||
|
default_data = data
|
||||||
|
end
|
||||||
|
if (not data.thread_channel) and next(configs) then
|
||||||
|
data.thread_channel = "itchy-" .. tostring(counter)
|
||||||
|
counter = counter + 1
|
||||||
|
end
|
||||||
|
configs[data] = data
|
||||||
|
return love.thread.newThread(thread_data):start(data)
|
||||||
|
end,
|
||||||
|
new_version = function(self, data)
|
||||||
|
if data == nil then
|
||||||
|
data = default_data
|
||||||
|
end
|
||||||
|
if data and configs[data] then
|
||||||
|
local channel = love.thread.getChannel(data.thread_channel or "itchy")
|
||||||
|
if channel:getCount() > 0 then
|
||||||
|
results[data] = channel:demand()
|
||||||
|
end
|
||||||
|
return results[data]
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
kill_version_checker = function(self, data)
|
||||||
|
if data == nil then
|
||||||
|
data = default_data
|
||||||
|
end
|
||||||
|
configs[data] = nil
|
||||||
|
results[data] = nil
|
||||||
|
if data == default_data then
|
||||||
|
default_data = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
return itchy
|
||||||
|
16
itchy.moon
16
itchy.moon
@ -4,15 +4,17 @@ thread = (...) ->
|
|||||||
import thread, timer from love
|
import thread, timer from love
|
||||||
|
|
||||||
http = require "socket.http"
|
http = require "socket.http"
|
||||||
_, libcurl = pcall -> return require "luajit-request"
|
ok, libcurl = pcall -> return require "luajit-request"
|
||||||
unless libcurl
|
unless ok
|
||||||
_, libcurl = pcall -> return require "lib.luajit-request"
|
ok, libcurl = pcall -> return require "lib.luajit-request"
|
||||||
|
libcurl = nil unless ok
|
||||||
|
|
||||||
request = (data) ->
|
request = (data) ->
|
||||||
result = {}
|
result = {}
|
||||||
unless libcurl
|
unless libcurl
|
||||||
if data.luajit_request
|
if data.luajit_request
|
||||||
_, libcurl = pcall -> return require data.luajit_request
|
ok, libcurl = pcall -> return require data.luajit_request
|
||||||
|
libcurl = nil unless ok
|
||||||
if libcurl
|
if libcurl
|
||||||
response = libcurl.send data.url or "https://api.itch.io/wharf/latest?target=#{data.target}&channel_name=#{data.channel}"
|
response = libcurl.send data.url or "https://api.itch.io/wharf/latest?target=#{data.target}&channel_name=#{data.channel}"
|
||||||
result.body = response.body
|
result.body = response.body
|
||||||
@ -109,20 +111,20 @@ configs, results = {}, {}
|
|||||||
local default_data
|
local default_data
|
||||||
|
|
||||||
itchy = {
|
itchy = {
|
||||||
check_version: (data) ->
|
check_version: (data) =>
|
||||||
default_data = data unless default_data
|
default_data = data unless default_data
|
||||||
if (not data.thread_channel) and next configs
|
if (not data.thread_channel) and next configs
|
||||||
data.thread_channel = "itchy-#{counter}"
|
data.thread_channel = "itchy-#{counter}"
|
||||||
counter += 1
|
counter += 1
|
||||||
configs[data] = data
|
configs[data] = data
|
||||||
love.thread.newThread(thread_data)\start data
|
love.thread.newThread(thread_data)\start data
|
||||||
new_version: (data=default_data) ->
|
new_version: (data=default_data) =>
|
||||||
if data and configs[data]
|
if data and configs[data]
|
||||||
channel = love.thread.getChannel data.thread_channel or "itchy"
|
channel = love.thread.getChannel data.thread_channel or "itchy"
|
||||||
if channel\getCount! > 0
|
if channel\getCount! > 0
|
||||||
results[data] = channel\demand!
|
results[data] = channel\demand!
|
||||||
return results[data] -- nil or data (new or old)
|
return results[data] -- nil or data (new or old)
|
||||||
kill_version_checker: (data=default_data) ->
|
kill_version_checker: (data=default_data) =>
|
||||||
configs[data] = nil
|
configs[data] = nil
|
||||||
results[data] = nil
|
results[data] = nil
|
||||||
default_data = nil if data == default_data
|
default_data = nil if data == default_data
|
||||||
|
Loading…
Reference in New Issue
Block a user