Page 1 of 1

Get installation directory of Moho

Posted: Sun May 21, 2006 10:36 am
by victo
Is there any script function to get the installation directory of Moho?

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


Thanks!

Posted: Thu May 25, 2006 8:00 am
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.

Posted: Tue May 30, 2006 5:09 pm
by rylleman
It doesn't work under windows.

Anyone knows what os.getenv variables there are?, how do I find out?, trial and error?

Posted: Wed May 31, 2006 10:19 am
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.