A centralized script system

Post Reply
User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

A centralized script system

Post by chris »

I'm unsure whether a similar incarnation of this script exists, but if not, here is a way to share scripts easily across sessions. To use it, make a script with the following code in it, and make sure it has a sysLoadEvent handler. Then, instead of importing scripts across profiles and having to do it over and over again with updates, write your code in .lua files, and store them in a common repository. My respository is my mudlet home dir+shared/. To load a script saved in here, do: loadShared('package name'). For larger packages with many subfiles, you can create a directory and load all the files within that directory with: loadSharedFolder('3k Mapper') (3K mapper being my shared directory).

What doesn't work: event handlers that are bound. Everything else works for me (including Geyser stuff so you can share your tabbed overlays easily, and have their load method bound to the resizewindow to keep them in the right proportions!)
Code: [show] | [select all] lua
function getBaseDir()
	local dir = getMudletHomeDir()
	local loc = string.find(dir, "[\\/]profiles[\\/]")
	local basedir = string.sub(dir, 0, loc)
	return basedir
end

function loadShared(filename)
	local newpath = getBaseDir()..'shared/'
	dofile(newpath..filename..'.lua')
end

function scandir(dirname)
--from http://www.wellho.net/resources/ex.php4?item=u112/dlisting
	callit = os.tmpname()
	os.execute("ls -a1 "..dirname .. " >"..callit)
	f = io.open(callit,"r")
	rv = f:read("*all")
	f:close()
	os.remove(callit)
	tabby = {}
	local from = 1
	local delim_from, delim_to = string.find( rv, "\n", from )
	while delim_from do
		table.insert( tabby, string.sub( rv, from , delim_from-1 ) )
		from = delim_to + 1
		delim_from, delim_to = string.find( rv, "\n", from )
	end
	-- table.insert( tabby, string.sub( rv, from ) )
	-- Comment out eliminates blank line on end!
	return tabby
	end

function loadSharedFolder(folder)
	local linuxfolder = string.gsub(folder,' ', '\\ ')
	local basedir = getBaseDir()..'shared/'
	local files = scandir(basedir..linuxfolder)
	local mudletdir = basedir..folder..'/'
	for i,v in pairs(files) do
		if v ~= '.' and v ~= '..' then
			dofile(mudletdir..v)
		end
	end
end

User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Re: A centralized script system

Post by chris »

Also, the directory listing is very specific to linux. Windows users will need to see how to get lua to list directories, and if you do please post it and i'll update it to address windows/linux specifics.

User avatar
Omni
Posts: 131
Joined: Fri Feb 12, 2010 10:26 am

Re: A centralized script system

Post by Omni »

can use the registerAnonymousEventHandler() function for event handlers.

Panorama
Posts: 3
Joined: Sun Jan 27, 2013 6:38 am

Re: A centralized script system

Post by Panorama »

Hey, I just started trying out Mudlet and I've been looking for something like this to keep scripts in sync between multiple profiles. Is this still the best way or have you found a better solution since then?

User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Re: A centralized script system

Post by chris »

Modules have replaced this system.

Panorama
Posts: 3
Joined: Sun Jan 27, 2013 6:38 am

Re: A centralized script system

Post by Panorama »

Got some pointers about modules? There doesn't seem to be much on the wiki.

User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Re: A centralized script system

Post by chris »

Sure, install by Toolbox -> Module Manager

If you choose to Save & Sync them, any changes you make while in the mudlet-editor will propagate to other modules. Priority is the load order, in case you have modules that depend on each other.

Post Reply