Page 2 of 2

Re: does lua support a run command?

Posted: Fri Apr 05, 2013 3:30 am
by substitute541
Jasoco wrote: Edit: I can't get this code to work...

Code: Select all

local os = love._os
if os == "OS X" then
	os.execute("open http://www.love2d.org")
elseif os == "Windows" then
	os.execute("start http://www.love2d.org")
elseif os == "Linux" then
	os.execute("xdg-open http://www.love2d.org")
else
	error("OS not detected as OS X, Windows or Linux!")
end
I get an error saying execute is a nil value. Am I using it wrong?
What happens when you just use Lua's os?

Re: does lua support a run command?

Posted: Fri Apr 05, 2013 3:38 am
by Jasoco
substitute541 wrote: What happens when you just use Lua's os?
Hey. Guess what. Guess what. I did that stupid thing newbies do where they accidentally overwrite important functions. It works when I type it correctly...

Code: Select all

function openURL(url)
	local os1 = love._os
	if os1 == "OS X" then
		os.execute("open "..url)
	elseif os1 == "Windows" then
		os.execute("start "..url)
	elseif os1 == "Linux" then
		os.execute("xdg-open "..url)
	else
		error("OS not detected as OS X, Windows or Linux!")
		-- Replace error with print or remove completely for released games to prevent accidental termination
	end
end
Silly me. Stupid silly me.

This code should work on all OS'. If it doesn't, let me know what happens.