LUA Version/ Platform Information

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
JC
Posts: 16
Joined: Fri Jun 02, 2006 9:30 am

LUA Version/ Platform Information

Post by JC »

Hi Folks,

I am coding using windows Lua Player. I want to display battery/memory information. The following works on my PSP but not on windows:

Code: Select all

screen:print (10,10,"battery: " .. System.powerGetBatteryLifePercent(),Color.new(255,255,255))
screen:print (10,30,"Free Mem: " .. System.getFreeMemory(),Color.new(255,255,255))

screen.flip()
screen.waitVblankStart()

pad = Controls.read()
while not pad:start() do
  pad = Controls.read()
end
When I run this with the windows Lua player I get the following error:
error: sysinfo.lua:4: attempt to call field `getFreeMemory' (a nil value)

So it looks like the getFreeMemory function is not support under windows. Fair enough I don't really need it supported under windows. That said I would like to be able to run this code under windows. Is it possible to tell what version/platform the lua player is so I could do something like

Code: Select all

if System.Platform() == "windows" then 
    FreeMem = 0
else 
   FreeMem = System.getFreeMemory()
end 

screen:print (10,30,"Free Mem: " .. FreeMem ,Color.new(255,255,255))

Thanks,
JC
Altair
Posts: 76
Joined: Sat May 20, 2006 2:33 am
Location: The Netherlands

Post by Altair »

I dont know if you can check what platform its on, but I know "_VERSION" holds the interpreters version. You could check it anyways to make sure :)
JC
Posts: 16
Joined: Fri Jun 02, 2006 9:30 am

Post by JC »

_VERSION returns LUA 5.0.2 on both windows and PSP.

Another thought I had was maybe I could suppress the error message, is that possible ?
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

perhaps since LUA checks for commands first

Check if they exist! as variables

if (System.powerGetBatteryLifePercent) then
do it here!

end
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

or change it up a bit, make a quick check at the beginning of the app to see what os it is on

currentos = ""
if System.powerGetBatteryLifePercent() then
currentos = "psp"
else
currentos = "pc"
end

and use the current os in all processes

function getPercent()
if currentos == "psp" then
return System.getBatteryLifePercent()
else
return "100"
end
end
- be2003
blog
JC
Posts: 16
Joined: Fri Jun 02, 2006 9:30 am

Post by JC »

Thanks guys,

Both your suggestions will enable me to acheive what I want.
Post Reply