Game Development Reference
In-Depth Information
that Lua runs in a much smaller memory space than other languages like Python.
This makes it a viable language even for console games. We successfully used Lua
on Drawn to Life for the Wii and even on Wedding Dash for the iPhone.
It is the simplicity and elegance of the language that won me over several years ago
when I started working with it. For these reasons and more, Lua is the language I
have chosen for this topic.
A Crash Course in Lua
Before I get into the details of how to integrate Lua into the game, I
d like to give you
a crash course in the language itself. This is by no means a complete language refer-
ence, but we ' ll explore the core language features.
'
Comments
Lua comments begin with two dashes:
-- This is a comment
There is also a block comment for commenting out across multiple lines. It uses dou-
ble square brackets, like this:
--[[
This is a single comment
that takes multiple lines.
--]]
As with any programming language, commenting your code is extremely important.
Since Lua is dynamically typed, it
'
s often hard to tell what an object is just by looking
at the code.
Variables
Lua is a dynamically typed language. That means that a variable can change its type
just by assigning something new to it:
x = 3 -- x is an integer
x = 3.14 -- now it
'
s a float
x=
s a string
Unlike C, variables aren
PI
-- now it
'
t
exist until the first line. The second line overwrites the contents of the variable, as
does the third line. There are eight basic types that Lua recognizes: number , string ,
Boolean , table , function , nil , userdata , and thread (more on these later).
'
t declared until they are used. In the above code, x doesn
'
 
 
 
 
Search WWH ::




Custom Search