Skip to content
Snippets Groups Projects
Commit 4c207f1c authored by dg's avatar dg
Browse files

threaded downloading of module list

git-svn-id: http://svn.net-core.org/repos/t-engine4@166 51575b47-30f0-44d4-a5cc-537603b46e54
parent ebd90d05
No related branches found
No related tags found
No related merge requests found
require "engine.class"
local lanes = require "lanes"
--- Handles dialog windows
module(..., package.seeall, class.make)
......@@ -105,3 +106,45 @@ function _M:loadSavefileDescription(dir)
return ls
end
end
--- Loads a list of modules from te4.org/modules.lualist
-- Calling this function starts a background thread, which can be waited on by the returned lina object
-- @param src the url to load the list from, if nil it will default to te4.org
-- @return a linda object (see lua lanes documentation) which should be waited upon like this <code>local mylist = l:receive("moduleslist")</code>. Also returns a thread handle
function _M:loadRemoteList(src)
local l = lanes.linda()
function list_handler(src)
require "socketed"
local http = require "socket.http"
local ltn12 = require "ltn12"
local t = {}
http.request{url = src, sink = ltn12.sink.table(t)}
local f, err = loadstring(table.concat(t))
if err then
print("Could not load modules list from ", src, ":", err)
l:send("moduleslist", {})
return
end
local list = {}
local dmods = {}
dmods.installableModule = function (t)
local ok = true
if not t.name or not t.long_name or not t.short_name or not t.author then ok = false end
if ok then
list[#list+1] = t
end
end
setfenv(f, dmods)
f()
l:send("moduleslist", list)
end
local h = lanes.gen("*", list_handler)(src or "http://te4.org/modules.lualist")
return l, h
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment