반응형
오늘은 시스템과 operating system Library에 대해 알아 보겠습니다.
시스템 정보를 얻어오는 함수입니다.
아래 소스를 보면서 정리하겠습니다.
local clock = os.clock ()
print("clock = " .. clock);
CPU 타임 1초동안 프로그램이 사용한 대략적인 시간입니다.
local date = os.date( "*t" ) -- returns table of date & time values
print( date.year, date.month ) -- print year and month
print( date.hour, date.min ) -- print hour and minutes
print( os.date( "%c" ) ) -- print out time/date string: e.g., "Thu Oct 23 14:55:02 2010"
날짜를 포맷에 맞게 출력합니다.
local t1 = os.time()
-- Print the elasped time
local function dspTime()
print( "Time elasped = " .. os.difftime( os.time(), t1) )
end
timer.performWithDelay( 2000, dspTime ) -- wait 2 second before calling
두 시간 동안의 차이를 출력합니다.
os.exit() -- exit app
앱을 종료합니다.
local destDir = system.DocumentsDirectory -- where the file is stored
local results, reason = os.remove( system.pathForFile( "apple.txt", destDir ) )
if results then
print( "file removed" )
else
print( "file does not exist", reason )
end
--> file does not exist apple.txt: No such file or directory
파일을 지웁니다.
local destDir = system.DocumentsDirectory -- where the file is stored
local results, reason = os.rename( system.pathForFile( "orange.txt", destDir ),
system.pathForFile( "apple.txt", destDir ) )
if results then
print( "file renamed" )
else
print( "file not renamed", reason )
end
--> file not renamed orange.txt: No such file or directory
파일 이름을 새로 바꿉니다.
local t = os.date( '*t' ) -- get table of current date and time
print( os.time( t ) ) -- print date & time as number of seconds
--> 1287516614
t.min = t.min + 1 -- add one to the minute field
print( os.time( t ) ) -- print number of seconds (increases by 60 seconds)
--> 1287516674
현재의 시간을 출력합니다.
os.execute( "ls" )
해당 os 명령어를 실행 합니다.
오늘 사용했던 소스는 아래에 있습니다.
system과 OS에 관련한 함수들을 살펴 봤습니다.
잘 이용하면 앱 만드는데 꽤 유용하게 쓰일 수 있습니다.
궁금한 점은 댓글을 이용해 주세요.
그럼 다음에 뵙겠습니다.
system.getInfo( param )
시스템 정보를 얻어오는 함수입니다.
시스템 함수를 사용해서 시스템 정보를 터미널에 뿌려주는 소스입니다.
아래 소스를 보면서 정리하겠습니다.
local sName = system.getInfo( "name" )
print("name = " .. sName);
디바이스의 이름을 출력합니다. iPhone에서는 iTunes에 나오는 이름이 출력됩니다.
local sModel = system.getInfo( "model" )
print("model = " .. sModel);
디바이스의 타입이 출력됩니다. (iPhone,iPad,iPhone Simulator,Droid,Galaxy Tab 등등)
local sDID = system.getInfo( "deviceID" )
print("deviceID = " .. sDID);
디바이스의 유니크한 아이디를 출력합니다.
local sEnv = system.getInfo( "environment" )
print("environment = " .. sEnv);
앱이 돌아가는 디바이스 환경을 출력합니다. 시뮬레이터인지 iOS인지 등등
local sPFN = system.getInfo( "platformName" )
print("platformName = " .. sPFN);
Mac OS X, Win, iPhone OS, Android 등 플랫폼(OS)의 이름을 출력합니다.
local sPFV = system.getInfo( "platformVersion" )
print("platformVersion = " .. sPFV);
플랫폼의 버전을 출력합니다.
local sVer = system.getInfo( "version" )
print("version = " .. sVer);
코로나 버전이 출력됩니다.
local sBul = system.getInfo( "build" )
print("build = " .. sBul);
local sTMU = system.getInfo( "textureMemoryUsed" )
print("textureMemoryUsed = " .. sTMU);
현재의 texture memory usage를 출력합니다.
local sMTS = system.getInfo( "maxTextureSize" )
print("maxTextureSize = " .. sMTS);
texture의 맥시멈 사이즈를 출력합니다.
local sArcInfo = system.getInfo( "architectureInfo" )
print("architectureInfo = " .. sArcInfo);
CPU architecture 정보를 출력합니다.
안드로이드는 주로 ARM, ARM Neon등이 출력되고 iOS는 iPhone1,1 iPhone1,2 등이 출력됩니다.
system.getPreference( category, name )
local sTime = system.getTimer()
print("system time = " .. sTime);
앱이 시작되고 난 다음의 시간이 출력됩니다.local sURL = system.openURL( "http://coronasdk.tistory.com" )
if(sURL) then print("OK") else print("No") end
URL을 오픈합니다. 결과 값은 true,false가 출력됩니다.
local sPath = system.pathForFile( "main.lua" )
print("sPath = " .. sPath);
해당 파일이 있는 경로를 출력합니다.
-- Set the measurement interval to 50 Hz.
-- This makes the system take 50 measurements per second.
system.setAccelerometerInterval( 50 )
system.setIdleTimer( true ) -- enable (turn on) the idle timer
system.setLocationAccuracy( 10 ) -- set GPS accuracy to 10 meters
GPS정확도를 10미터로 합니다.
system.setLocationThreshold( 100 ) -- fire the location event every 100 meters
100미터마다 로케이션 이벤트를 줍니다.
system.vibrate()
진동을 줍니다.
System-defined directories
system.DocumentsDirectory - persist하게 유지될 필요가 있는 파일에 사용됩니다.
system.TemporaryDirectory - 일시적으로 필요한 파일에 사용됩니다.
system.ResourceDirectory - 리소스가 있는 디렉토리 입니다. 다운 받거나 하게 되면 이곳에 파일이 저장 됩니다. 이곳에 있는 파일은 개발자 임의로 생성,제거,수정 하면 안됩니다. 앱이 실행 될 때 이곳의 정보를 읽기 때문에 이 정보가 맞지 않으면 앱이 실행되지 않을 수도 있습니다.
OS Library
다음은 OS 에 대한 정보 입니다.
아래 소스를 보면서 정리하겠습니다.
local clock = os.clock ()
print("clock = " .. clock);
CPU 타임 1초동안 프로그램이 사용한 대략적인 시간입니다.
local date = os.date( "*t" ) -- returns table of date & time values
print( date.year, date.month ) -- print year and month
print( date.hour, date.min ) -- print hour and minutes
print( os.date( "%c" ) ) -- print out time/date string: e.g., "Thu Oct 23 14:55:02 2010"
날짜를 포맷에 맞게 출력합니다.
local t1 = os.time()
-- Print the elasped time
local function dspTime()
print( "Time elasped = " .. os.difftime( os.time(), t1) )
end
timer.performWithDelay( 2000, dspTime ) -- wait 2 second before calling
두 시간 동안의 차이를 출력합니다.
os.exit() -- exit app
앱을 종료합니다.
local destDir = system.DocumentsDirectory -- where the file is stored
local results, reason = os.remove( system.pathForFile( "apple.txt", destDir ) )
if results then
print( "file removed" )
else
print( "file does not exist", reason )
end
--> file does not exist apple.txt: No such file or directory
파일을 지웁니다.
local destDir = system.DocumentsDirectory -- where the file is stored
local results, reason = os.rename( system.pathForFile( "orange.txt", destDir ),
system.pathForFile( "apple.txt", destDir ) )
if results then
print( "file renamed" )
else
print( "file not renamed", reason )
end
--> file not renamed orange.txt: No such file or directory
파일 이름을 새로 바꿉니다.
local t = os.date( '*t' ) -- get table of current date and time
print( os.time( t ) ) -- print date & time as number of seconds
--> 1287516614
t.min = t.min + 1 -- add one to the minute field
print( os.time( t ) ) -- print number of seconds (increases by 60 seconds)
--> 1287516674
현재의 시간을 출력합니다.
os.execute( "ls" )
해당 os 명령어를 실행 합니다.
오늘 사용했던 소스는 아래에 있습니다.
system과 OS에 관련한 함수들을 살펴 봤습니다.
잘 이용하면 앱 만드는데 꽤 유용하게 쓰일 수 있습니다.
궁금한 점은 댓글을 이용해 주세요.
그럼 다음에 뵙겠습니다.
반응형
'Corona SDK > Corona Doc' 카테고리의 다른 글
Corona SDK Native UI (0) | 2011.11.07 |
---|---|
Location and Maps (0) | 2011.11.04 |
이벤트, 리스너로 다이나믹한 표현 하기 3 (4) | 2011.11.03 |
이벤트, 리스너로 다이나믹한 표현 하기 2 (4) | 2011.11.02 |
이벤트, 리스너로 다이나믹한 표현 하기 1 (0) | 2011.11.01 |
코로나 네트워킹 과 웹 서비스 3 (In App Purchase 1) (2) | 2011.10.25 |
코로나 네트워킹 과 웹 서비스 2 (0) | 2011.10.24 |
코로나 네트워킹 과 웹 서비스 1 (0) | 2011.10.21 |
오디오, 비디오, 사진 컨트롤 2 (4) | 2011.10.20 |
오디오, 비디오, 사진 컨트롤 1 (0) | 2011.10.19 |