In any application, it is often required for to access Operating
System level functions and it is made available with Operating System
library. The list of functions available are listed in the following
table.
Common OS functions
A simple example using common math functions is shown below.-- Date with format io.write("The date is ", os.date("%m/%d/%Y"),"\n") -- Date and time io.write("The date and time is ", os.date(),"\n") -- Time io.write("The OS time is ", os.time(),"\n") -- Wait for some time for i=1,1000000 do end -- Time since Lua started io.write("Lua started before ", os.clock(),"\n")When we run the above program, we will get similar output to the following.
The date is 01/25/2014 The date and time is 01/25/14 07:38:40 The OS time is 1390615720 Lua started before 0.013The above examples are just a few of the common examples, we can use OS library based on our need, so try using all the functions to be more familiar. There are functions like remove which helps in removing file, execute that helps us executing OS commands as explained above.
No comments:
Post a Comment