Game Development Reference
In-Depth Information
os.time ( [table] )
This function returns the current time when called without arguments. The table passed as
parameters should have the fields set to at least year , month , and day . Other fields, such as hour ,
min , sec , and idist , are optional.
os.tmpname ( )
This function returns a string with a filename that can be used for a temporary file. This file needs to
be explicitly opened and explicitly removed when not required. This is different from an io.tmpfile
function (discussed in the next chapter), which automatically removes the file when the program ends.
Tables: A Quick Overview
I have noted that tables are one of the many types of variables available in Lua. Though it might
sound trivial, tables are the backbone of Lua, and they're used in many ways: as arrays, hash tables
(associative arrays), and objects, and in plenty more. The following subsections will discuss tables
as arrays and hash tables.
Tables As Arrays
The Lua equivalent of an array is a table. All arrays in Lua have an index base of 1, which means that
the first entry starts at 1 (not 0, as in many other languages). Arrays need to have a numeric index.
These can be multidimensional and do not need to be dimensioned at declaration. These can grow
and be redimensioned at runtime.
local theArray = {}
for i = 1, 10 do
theArray[i] = "item ". . i
end
Tables As Associative Arrays
Tables are the Lua equivalent of associative arrays, hash tables, and even NSDictionary objects. The
difference between an array and an associative array is that, instead of having a numeric index to
access an element of the array table, an associative array can use a string to access the elements.
local theTable = {}
for i = 1, 10 do
theTable["item"..i] = i
end
Note
Lua is very flexible and hence is very forgiving, even if you mix the two types of arrays.
 
 
Search WWH ::




Custom Search