does lua support some kind of run command ?
to start programs.
does lua support a run command?
- 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?
Be careful when using os.* commands though. Löve is cross-platform and should stay that way, but not all OS' have all the same commands. Does os.execute even work on OS X or Linux?
It would be nice if the Löve API could offer a wrapper for us to use when we need to launch things like URL's or open folders. (Within permission reasons of course) For instance, a link in an About/Credits screen that opens up the developer's website/FaceBook/Twitter/MySpace* page. Or one that can open specific folder directories, like how MineCraft has a button to open the Texture Pack folder. At least by providing API's for this stuff we can avoid risking alienating some users when a command ends up being Windows only or something. (Like how the Texture Pack button in Minecraft didn't even work on OS X for years before they fixed it.)
*What's MySpace? It's a website where bands go to talk to eachother.
It would be nice if the Löve API could offer a wrapper for us to use when we need to launch things like URL's or open folders. (Within permission reasons of course) For instance, a link in an About/Credits screen that opens up the developer's website/FaceBook/Twitter/MySpace* page. Or one that can open specific folder directories, like how MineCraft has a button to open the Texture Pack folder. At least by providing API's for this stuff we can avoid risking alienating some users when a command ends up being Windows only or something. (Like how the Texture Pack button in Minecraft didn't even work on OS X for years before they fixed it.)
*What's MySpace? It's a website where bands go to talk to eachother.
- master both
- Party member
- Posts: 262
- Joined: Tue Nov 08, 2011 12:39 am
- Location: Chile
Re: does lua support a run command?
os.execute works on my ubuntu, also in Mari0, on the "select map" option, you can press "m" and the maps packs folder pop up, but i dont know how did he do it
- 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?
Well, the Maps Pack folder is inside the "Working Directory" for the game so it'd be simple enough.master both wrote:os.execute works on my ubuntu, also in Mari0, on the "select map" option, you can press "m" and the maps packs folder pop up, but i dont know how did he do it
It would be harder to execute applications, though I don't think there's any reason we should need to.
But URL's would be nice. Can os.execute execute a URL? It would be a trivial thing to do as every OS has a browser and it would just send the command to open it in the default browser.
I'd still like a proper Löve wrapper API for it though. Part of love.filesystem of course like love.filesystem.openfolder() or love.filesystem.openurl().
Edit: LOL, looking through Mari0's code to find the function for opening the folder and I notice his comment about not using a GUI Library because he's lazy. Personally I programmed my own menu GUI library because I simply didn't want to use anyone elses.
Anyway, here's the code Maurice uses for opening the "save folder":
Code: Select all
function openSaveFolder(subfolder) --By Slime
local path = love.filesystem.getSaveDirectory()
path = subfolder and path.."/"..subfolder or path
local cmdstr
local successval = 0
if os.getenv("WINDIR") then -- lolwindows
--cmdstr = "Explorer /root,%s"
if path:match("LOVE") then --hardcoded to fix ISO characters in usernames and made sure release mode doesn't mess anything up -saso
cmdstr = "Explorer %%appdata%%\\LOVE\\mari0"
else
cmdstr = "Explorer %%appdata%%\\mari0"
end
path = path:gsub("/", "\\")
successval = 1
elseif os.getenv("HOME") then
if path:match("/Library/Application Support") then -- OSX
cmdstr = "open \"%s\""
else -- linux?
cmdstr = "xdg-open \"%s\""
end
end
-- returns true if successfully opened folder
return cmdstr and os.execute(cmdstr:format(path)) == successval
end
I used a different method that I haven't tested much so I don't even know if it properly works, but it's simpler in its OS check:
Code: Select all
local add = love.filesystem.getAppdataDirectory()
if string.sub(add, -7) == "Support" then
ACCOUNT_FOR_WIDGETS = 44 --OS X - Menubar (22) + Titlebar (22) (Not including Dock)
USERS_OS = "osx"
else
ACCOUNT_FOR_WIDGETS = 70 --Windows 7 Taskbar (40) + Titlebar (30)
USERS_OS = "win7"
end
- slime
- Solid Snayke
- Posts: 3170
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: does lua support a run command?
You can get the current operating system with the love._os string. It will return "Windows", "OS X", or "Linux". It got added to 0.8.0 at the last minute, just slightly after Mari0 was released IIRC, so that code doesn't have it.
- 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?
Oh, awesome! That's cool. I would have expected something simpler. Is that in the Wiki? Are there any other hidden things like that?slime wrote:You can get the current operating system with the love._os string. It will return "Windows", "OS X", or "Linux". It got added to 0.8.0 at the last minute, just slightly after Mari0 was released IIRC, so that code doesn't have it.
We still should have an API for opening folders and URL's without a bunch of code though. Just for simplicity's sake.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: does lua support a run command?
No, it can't. os.execute is basically entering a line in your terminal window. I think in Windows you can do "open http://love2d.org/", and on Linux "xdg-open http://love2d.org/", but I don't know how it is for OS X.Jasoco wrote:But URL's would be nice. Can os.execute execute a URL? It would be a trivial thing to do as every OS has a browser and it would just send the command to open it in the default browser.
It might be a good idea to add a love.openinbrowser() function or something. It would be disabled by default in SELÖVE, of course.
Help us help you: attach a .love.
- 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?
Tried the open command Robin said in the command prompt, gives me an error saying that "open" is an invalid command.
Currently designing themes for WordPress.
Sometimes lurks around the forum.
Sometimes lurks around the forum.
- 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?
On OS X it's apparently just "open http://www.love2d.org/".Robin wrote:No, it can't. os.execute is basically entering a line in your terminal window. I think in Windows you can do "open http://love2d.org/", and on Linux "xdg-open http://love2d.org/", but I don't know how it is for OS X.Jasoco wrote:But URL's would be nice. Can os.execute execute a URL? It would be a trivial thing to do as every OS has a browser and it would just send the command to open it in the default browser.
It might be a good idea to add a love.openinbrowser() function or something. It would be disabled by default in SELÖVE, of course.
Apparently on Windows (At least 7) it's "start http://www.love2d.org/" instead of "open".
Edit: I can't get this code to work...
...
I get an error saying execute is a nil value. Am I using it wrong?
Edit: Fixed and correct on next page...
Last edited by Jasoco on Fri Apr 05, 2013 3:39 am, edited 1 time in total.
Who is online
Users browsing this forum: No registered users and 6 guests