Game Development Reference
In-Depth Information
getmetatable ( object )
This function retrieves the metatable associated with the object. It returns nil if there is no metatable
present. This is mostly used to add functionality to an object table. In some cases, this is also used
as a signature of the object. So while the type function does not tell you much, the metatables can
be compared with a list of known metatable signatures to get more information.
ipairs ( t )
This function returns a function that returns three values, an iterator function, the table t and 0. It
works with the array tables only. The following code will iterate over the pairs up to the first integer
key missing from the table:
t = {1,2,3,4,test = "test",5,6}
t[3] = nil
for i,v in ipairs(t) do
-- body
print(i,v)
end
load ( func [,chunkname] )
This function is similar to the dofile command; it loads a chunk using the function func . Each
time the function is called, the function must return a string that concatenates with the previous
result. When the chunk is complete, it returns nil and an error message. The chunkname is used for
debugging. When the function is called and an error occurs, Lua displays debugging information,
including the line number where the error occurred and the name of the Lua file in which the error
occurred. When we have compiled chunks, there is no filename and hence, for debugging purposes,
it is up to you, the developer, to provide that information in the form of the chunkname parameter.
loadstring ( string [,chunkname] )
This function is similar to load , but instead of loading the compiled bytecode from a file, it takes the
compiled code (chunk) from a string.
loadstring(compiledChunk, "OurChunk")
next ( table [,index] )
This function allows the program to iterate through all the fields of a table. The function returns
multiple values. Internally, the function takes on system commands.
t = {"One", "Deux", "Drei", "Quarto"}
print(next(t, 3))
 
Search WWH ::




Custom Search