Standard Lua Libraries included with Mudlet?

Post Reply
kkerwin1
Posts: 22
Joined: Tue Apr 20, 2010 7:37 am

Standard Lua Libraries included with Mudlet?

Post by kkerwin1 »

I'm curious as to what standard Lua libraries are shipped with Mudlet.

Specifically, I'm writing a script that will require the socket module. The reason is to produce a script to crowd-source the creation of a beastiary database/website for the Achaea mud. Without the socket module, my Lua scripts have no way to communicate with a server other than the Mud server. If it's not included, I'll just have to figure out a way to get it to others.

kkerwin1
Posts: 22
Joined: Tue Apr 20, 2010 7:37 am

Re: Standard Lua Libraries included with Mudlet?

Post by kkerwin1 »

Oh, I suppose I should add: I'm running Linux at the moment, and don't have access to either a Windows or Mac machine to just test it with a script.

Still, having a full list of what libraries are included would be nice, too. :D

User avatar
kevutian
Posts: 217
Joined: Fri Aug 20, 2010 8:18 pm
Location: United Kingdom
Contact:

Re: Standard Lua Libraries included with Mudlet?

Post by kevutian »

Going off the top of my head here, so I may miss some, but:

LuaFilesystem,
LuaZip,
Lrexlib and LuaSQLite.

As for socket support, just pull in liblua-5.1-socket0 and require() it inside your scripts.

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: Standard Lua Libraries included with Mudlet?

Post by demonnic »

As a sort of hacky hack hack way of doing it, you could code the server to parse http GET requests, and then use downloadFile() to communicate with the server. The file downloaded would be the payload back from the server, which you could then parse using file io.

It's not exactly behaving by the right rules to be a REST interface, but it's kind of the same idea.


ETA: JSON would be extremely well suited to this, as we include YAJL bindings with yajl.to_string and yajl.to_value to shift from lua table to a string of JSON and vice versa.

kkerwin1
Posts: 22
Joined: Tue Apr 20, 2010 7:37 am

Re: Standard Lua Libraries included with Mudlet?

Post by kkerwin1 »

Thanks to both of you guys for chiming in. I appreciate it.
kevutian wrote: As for socket support, just pull in liblua-5.1-socket0 and require() it inside your scripts.
The problem with this is that the script is meant for wide consumption. That means that a requirement to run the script will be to download the entire Lua distribution. While that's not hard per se, it is one extra step for my users to do, and will decrease the number who use it, thus decreasing the ability for us to crowd-source collection of data.
demonnic wrote:As a sort of hacky hack hack way of doing it, you could code the server to parse http GET requests, and then use downloadFile() to communicate with the server. The file downloaded would be the payload back from the server, which you could then parse using file io.

It's not exactly behaving by the right rules to be a REST interface, but it's kind of the same idea.


ETA: JSON would be extremely well suited to this, as we include YAJL bindings with yajl.to_string and yajl.to_value to shift from lua table to a string of JSON and vice versa.
If I'm understanding you correctly, the URL of the item that they are "GETting" would be all of the code that I need. Example:

downloadFile(http://mysites.url.com/makePost.html?de ... a=someArea)

Edit for clarity: makepost.html?denizenName=someName,denizenLavel=someLevel,area=someArea

Et cetera. The downloaded "file" doesn't actually exist, but the URL would provide the server with the info that it needs to construct the database entry. The server could optionally reply with a meaningful file constructed of this information, an empty file, or something else equally meaningless and subsequently overwritten the next time a post is made.

Intriguing. It's dirty, but it gets the job done, I guess. And without needing the user to do any extra work.

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: Standard Lua Libraries included with Mudlet?

Post by demonnic »

Yeah, you just map the urls to method/function calls, like in a standard REST . You just only use GET. Then the data you return can be a json string that you can turn into a lua table. You just have to read it from the file you download. Or ignore the file if you don't need a return value.

User avatar
kevutian
Posts: 217
Joined: Fri Aug 20, 2010 8:18 pm
Location: United Kingdom
Contact:

Re: Standard Lua Libraries included with Mudlet?

Post by kevutian »

Ended up needing this myself. Hopefully others can make use of it.
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()
	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

	return dependResult
end

function packageDownload()

end

User avatar
kevutian
Posts: 217
Joined: Fri Aug 20, 2010 8:18 pm
Location: United Kingdom
Contact:

Re: Standard Lua Libraries included with Mudlet?

Post by kevutian »

Ignore my random function calls. Just strip them out, of course.

Post Reply