Get installation directory of Moho

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
victo
Posts: 1
Joined: Sun May 21, 2006 7:09 am

Get installation directory of Moho

Post by victo »

Is there any script function to get the installation directory of Moho?

e.g. "C:\program files\Moho"


Thanks!
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

Under Linux, Moho creates an environment variable, you can get it with

os.getenv("MOHO_LOCATION")

This is the path and name of the executable file. I don't know how this works on other operating systems.
- - - Fazek
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Post by rylleman »

It doesn't work under windows.

Anyone knows what os.getenv variables there are?, how do I find out?, trial and error?
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Post by Fazek »

Hello,

Can someone try for me on Windows and Mac that the os.popen() function of lua is working or not? This is a new function of lua 5.1 and it is OK in the Linux version of Moho. My problem is that the os.tmpname() function is not available under Linux, so I can't get the output of os.execute(). For example, try the following script:

Code: Select all

function trythis:ListDir()
--print the contents of the current directory
	local opSys= os.getenv("OS")
	local dirCmd= "ls ."

	if (opSys) then
		if (string.lower(string.sub(opSys, 1, 3)) == "win") then
			dirCmd= "dir ."
		end
	end
	print(self:OS_Execute(dirCmd))
end

function trythis:OS_Execute(cmd)
--os.execute, return: standard output, as string
--based on the "luaforge.net/projects/hamster" routines

	local f= io.popen(cmd)

	if (f) then
		local str= f:read("*a")
		f:close()
		return str
	end
	return ""
end
Thank you in advance!

Handling directories is a pain in lua. I think if you want to use the install directory, the best way is to ask the user where to find it (maybe there are more than one installed moho on a computer or on a network!). Then you can keep the path in the preferences.
- - - Fazek
Post Reply