Game Development Reference
In-Depth Information
Chapter 2
Lua Libraries
In the previous chapter, you learned the reasons behind Lua and that Lua is, after all, made up of
C code libraries. One of the advantages that the developers of Lua got from this architecture for Lua
was that they could add functionality as required. Adding functionality involved writing new functions
and making them available in Lua. It is quite a surprise that Lua does not have multiple distributions
and remains as intended by the developers; there are not many modified versions. However, many
developmental studios do modify, or rather adapt and customize, Lua for their own editors and tools.
In this chapter, we shall look at the standard Lua libraries and namespaces that provide us with their
functions. Then we'll have a detailed look at the system- and table-related functions.
Basic Functions
Lua has some basic functions that are part of the Lua system, we'll have a look at the following
subsections. These form part of the core library and are generally available to most of the
distributions.
assert ( v [, message] )
This function is similar to the assert function used with C; it returns an error if the value of the
argument v is false (either nil or false );. The message, if present, is displayed as an error; if absent,
the default text “assertion failed!” is displayed.
assert(money>0,"you need to have some money to buy something")
collectgarbage ( [opt [,arg]] )
This function is a generic interface to the garbagecollector . The function acts differently depending
on the parameter opt . The options that you can pass to this function as opt are
13
 
Search WWH ::




Custom Search