does lua support a run command?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: does lua support a run command?

Post 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?
Currently designing themes for WordPress.

Sometimes lurks around the forum.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: does lua support a run command?

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests