Game Development Reference
In-Depth Information
Figure 2-1. The output of the function in Lua running in the terminal
Notice that the functions are declared differently, but the output of both is the same. In short, you
can say that obj:func() is the same as calling obj.func(obj) .
Note It is very easy to forget about the way you might have declared the function and hence end
up calling it a different way, which can cause some hiccups in your code where a parameter passed
would get shifted and give you strange results. To avoid that, keep a consistent method of declaring and
calling functions.
From that last example, one question that might come to mind is, When do you use a single dot
( . ) and when do you use a colon ( : ) if Lua is not an object-oriented language? Why would you ever
need that? In order to answer these questions, let's work on an object and give it some functionality.
This sample doesn't use objects or external files, so it can be run in the Lua interactive console
without any problems.
Search WWH ::




Custom Search