io.popen not available on mac?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

io.popen not available on mac?

Post by Germanunkol »

Hi, I have a user who can't run my game on a mac, he gets this error message:
http://cl.widerwille.com/NBud

This is the code (note: when I got the error, I used io.open without the pcall - otherwise I would not have gotten the error message).

Code: Select all

function getCPUNumber()
	ok, f = pcall(io.popen,"nproc")
	if ok and f then
		local n = f:read("*a")
		f:close()
		return tonumber(n)
	end
end
Anyone know a workaround for this? How do I get the number of CPUs on a Mac if this way does not work?

Using Löve 0.8.0
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: io.popen not available on mac?

Post by Taehl »

http://www.lua.org/manual/5.1/manual.html#pdf-io.popen
Lua Manual 5.1 wrote:This function is system dependent and is not available on all platforms.
So, nope, looks like it's not available on Mac.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: io.popen not available on mac?

Post by slime »

It is technically available on OSX, but it doesn't work in the particular build of Lua that 0.8.0 for OSX is packaged with, for whatever reason. If you use a version of LÖVE built with LuaJIT, it should work fine.

EDIT: I just built LÖVE 0.8.0 using a fixed/upgraded version of Lua 5.1. io.popen should work now, and as a bonus it uses OpenAL Soft instead of Apple's buggy OpenAL implementation, so many OSX-specific audio bugs should be fixed as well. Here it is: https://dl.dropbox.com/u/4214717/love-osx.zip

Note that the "nproc" command isn't available in OSX. If you want to get the number of physical cores in OS X, you can use something like this command:

Code: Select all

io.popen("system_profiler SPHardwareDataType | grep -i 'total number of cores'")
It will produce a string like this, which you can parse: " Total Number of Cores: 4"

Or if you don't mind including Intel's hyperthreading in the core count, this should work in OS X:

Code: Select all

io.popen("sysctl -n hw.ncpu")
It produces a string like "8".

To detect the operating system the user is running, you can check the love._os string. It will return "Windows", "Linux", "OS X", or "Unknown".
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: io.popen not available on mac?

Post by Lafolie »

Oh awesome slime, I'll be grabbing that build! I take it these issues are *fixed* in the next official build?
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: io.popen not available on mac?

Post by slime »

Lafolie wrote:Oh awesome slime, I'll be grabbing that build! I take it these issues are *fixed* in the next official build?
If by *fixed* you mean the next LÖVE version will use the same updated/fixed libraries as the 0.8.0 build I just uploaded, then yes. :)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: io.popen not available on mac?

Post by bartbes »

Hehe, slime is afraid of me, I see.
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: io.popen not available on mac?

Post by Germanunkol »

slime wrote:It is technically available on OSX, but it doesn't work in the particular build of Lua that 0.8.0 for OSX is packaged with, for whatever reason. If you use a version of LÖVE built with LuaJIT, it should work fine.

EDIT: I just built LÖVE 0.8.0 using a fixed/upgraded version of Lua 5.1. io.popen should work now, and as a bonus it uses OpenAL Soft instead of Apple's buggy OpenAL implementation, so many OSX-specific audio bugs should be fixed as well. Here it is: https://dl.dropbox.com/u/4214717/love-osx.zip

Note that the "nproc" command isn't available in OSX. If you want to get the number of physical cores in OS X, you can use something like this command:

Code: Select all

io.popen("system_profiler SPHardwareDataType | grep -i 'total number of cores'")
It will produce a string like this, which you can parse: " Total Number of Cores: 4"

Or if you don't mind including Intel's hyperthreading in the core count, this should work in OS X:

Code: Select all

io.popen("sysctl -n hw.ncpu")
It produces a string like "8".

To detect the operating system the user is running, you can check the love._os string. It will return "Windows", "Linux", "OS X", or "Unknown".
Thanks!
This is sort of what I was looking for. But this means I can't let users use the offiical build of Löve - and that kinda sucks. Can anyone think of a way to get the CPU count with the normal Löve 0.8.0? If not, I'll have to tell Mac users to download this one...
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: io.popen not available on mac?

Post by slime »

You could use os.execute and save the output of the commands to a file in the LÖVE save directory, then read that back. Something like this:

Code: Select all

os.execute(string.format("%s > \"%s\"", "sysctl -n hw.ncpu", love.filesystem.getSaveDirectory().."/cores.txt"))

if love.filesystem.isFile("cores.txt") then
    local corestxt = love.filesystem.read("cores.txt")
end
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: io.popen not available on mac?

Post by Germanunkol »

Perfect, thank you. os.execute it is...

Just wondering... you could use %q instead of %s to avoid having to escape the quotes, right? Would be a little prettier...
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Post Reply

Who is online

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