Mudlet Lua Module Loader

Share your scripts and packages with other Mudlet users.
Post Reply
User avatar
kevutian
Posts: 217
Joined: Fri Aug 20, 2010 8:18 pm
Location: United Kingdom
Contact:

Mudlet Lua Module Loader

Post by kevutian » Sat Jun 01, 2013 1:33 pm

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!)
Code: [show] | [select all] lua
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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests