Page 1 of 1
Mudlet Lua Module Loader
Posted: Sat Jun 01, 2013 1:33 pm
by kevutian
Seems I posted this on another thread, but I feel it really deserves its own.
I won't bother explaining it as those people who will use something like this will see for themselves. (Nerf reinventing the wheel!)
function fileExists(fname)
local f = io.open(fname, "r")
if f then
f:close()
return true
else
return false
end
end
function dependencyCheck()
if not isinit then return false end
local dependencies = {
luaSocket = {
"%U/AppData/Local/Mudlet/socket/core.dll",
"%H/socket/core.dll"
},
}
local dependResult = {}
local userFolder = string.match(getMudletHomeDir(), "^(.-)[\\/]%.config")
local homeDir = getMudletHomeDir()
for lib, locations in pairs(dependencies) do
dependResult[lib] = false
for _, location in ipairs(locations) do
local fullpath = location:gsub("%%U", userFolder):gsub("%%H", homeDir)
if fileExists(fullpath) then
dependResult[lib] = true
break
else
--disconnect()
--warning("LuaSocket not found: Connection aborted.\n")
--local putthisinyourpipe = tempTimer(1, [[info("Downloading package files...");packageDownload()]])
end
end
end
isinit = true
return dependResult
end
function packageDownload()
downloadFile(getMudletHomeDir() .. "/socket.zip", "http://api.pharanyx.com/saracen/socket.zip")
end
Works for Windows only at the moment.