Skip to content

Commit

Permalink
fixed typos, v3 ready
Browse files Browse the repository at this point in the history
  • Loading branch information
TangentFoxy committed May 26, 2018
1 parent 90056af commit 93aa79a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
55 changes: 50 additions & 5 deletions itchy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@ thread = function(...)
thread, timer = _obj_0.thread, _obj_0.timer
end
local http = require("socket.http")
local _, libcurl = pcall(function()
local ok, libcurl = pcall(function()
return require("luajit-request")
end)
if not (libcurl) then
_, libcurl = pcall(function()
if not (ok) then
ok, libcurl = pcall(function()
return require("lib.luajit-request")
end)
if not (ok) then
libcurl = nil
end
end
local request
request = function(data)
local result = { }
if not (libcurl) then
if data.luajit_request then
_, libcurl = pcall(function()
ok, libcurl = pcall(function()
return require(data.luajit_request)
end)
if not (ok) then
libcurl = nil
end
end
end
if libcurl then
Expand Down Expand Up @@ -58,7 +64,6 @@ thread = function(...)
send:push(result)
return false
end
local ok
ok, result = request(data)
if not (ok) then
send:push(result)
Expand Down Expand Up @@ -134,3 +139,43 @@ end
if not (love.graphics or love.window) then
return thread(...)
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 changes: 9 additions & 7 deletions itchy.moon
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ thread = (...) ->
import thread, timer from love

http = require "socket.http"
_, libcurl = pcall -> return require "luajit-request"
unless libcurl
_, libcurl = pcall -> return require "lib.luajit-request"
ok, libcurl = pcall -> return require "luajit-request"
unless ok
ok, libcurl = pcall -> return require "lib.luajit-request"
libcurl = nil unless ok

request = (data) ->
result = {}
unless libcurl
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
response = libcurl.send data.url or "https://api.itch.io/wharf/latest?target=#{data.target}&channel_name=#{data.channel}"
result.body = response.body
Expand Down Expand Up @@ -109,20 +111,20 @@ configs, results = {}, {}
local default_data

itchy = {
check_version: (data) ->
check_version: (data) =>
default_data = data unless default_data
if (not data.thread_channel) and next configs
data.thread_channel = "itchy-#{counter}"
counter += 1
configs[data] = data
love.thread.newThread(thread_data)\start data
new_version: (data=default_data) ->
new_version: (data=default_data) =>
if data and configs[data]
channel = love.thread.getChannel data.thread_channel or "itchy"
if channel\getCount! > 0
results[data] = channel\demand!
return results[data] -- nil or data (new or old)
kill_version_checker: (data=default_data) ->
kill_version_checker: (data=default_data) =>
configs[data] = nil
results[data] = nil
default_data = nil if data == default_data
Expand Down

0 comments on commit 93aa79a

Please sign in to comment.