Game Development Reference
In-Depth Information
So what is Lua like?
At the heart of Lua (which means moon in Portuguese), you have the table. You may think
of it as being similar to a JavaScript object, only it's much more than that. It plays the part
of arrays, dictionaries, enumerations, structures, and classes, among other things. It makes
Lua the perfect language to manage large sets of data. You write a script that handles the
data, and then keep feeding it different "stuff." An inventory or shop system, an interactive
children's topic—these types of projects could all benefit from Lua's table-centric power, as
they can be built around a fixed template with a data table at its core.
Its syntax, for those not used to a scripting language, can be a little odd, with its dos, thens,
and ends. But once you get past this initial hurdle, you'll find Lua quite user-friendly. Here
are some of the "oddities" in its syntax:
-- a comment
--[[
a
multiline
comment
]]
-- a table declared as a local variable
local myTable = {}
-- the length of a table
local len = #myTable
-- looping the table (starting with index 1!)
for i = 1, #myTable do
local element = myTable[i]
-- an if elseif else statement
if (element ~= true ) then
-- do something
elseif (element == true) then
-- do something else
else
-- we'll never get here!
end
end
Search WWH ::




Custom Search