Apps are the hottest new medium for interaction. But conventional technologies make creating graphically-rich, interactive content an enormous challenge. Learn how Corona SDK enables you to build apps 10x more quickly, whether you are a creative coder or a visual designer.
26. coronalabs.com@walterluh
Lua vs Other Languages
if
(!carMoving)
{
//
do
something
}
else
if
(noGas)
{
//
do
something
else
}
for
(i=1;
i<=10;
i++)
{
print(i)
}
for
(j=100;
j>0;
j-‐-‐)
{
print(j)
}
if
(not
carMoving)
then
-‐-‐
do
something
elseif
(noGas)
then
-‐-‐
do
something
else
end
for
i
=
1,10
do
print(i)
end
for
j
=
100,1,-‐1
do
print(j)
end
27. coronalabs.com@walterluh
array
=
{
"a",
"b",
100,
"hello"
}
dictionary
=
{
x=5,
y=7,
name="Joe"
}
t
=
{}
-‐-‐
empty
table
t[1]
=
"a"
-‐-‐
numerical
index
t["x"]
=
5
-‐-‐
key
index
t.x
=
5
-‐-‐
equivalent
property
access
t.hasProperties
=
true
t[array]
=
"Joe"
-‐-‐
any
type
can
be
a
key!!!
t["printJoe"]
=
function()
print("Joe")
end
Lua objects areTables
28. coronalabs.com@walterluh
-‐-‐
create
empty
table
local
o
=
{}
-‐-‐
add
method
function
o:saySomething(
something
)
print(
something
)
end
-‐-‐
output
'hi'
o:saySomething(
"hi!"
)
Object methods
29. coronalabs.com@walterluh
-‐-‐
create
empty
table
local
o
=
{}
-‐-‐
add
method
local
function
f(
self,
something
)
print(
something
)
end
o.saySomething
=
f
-‐-‐
output
'hi'
o.saySomething(
o,
"hi!"
)
The ':' is syntactic sugar
30. coronalabs.com@walterluh
Arrays are 1-based
//
Other
languages:
index
begins
with
0
array=['a','b','c'];
for
(
var
i=0;
i<arr.length;
i++)
{
log(
array[i]
)
}
-‐-‐
Lua:
index
begins
with
1
local
array
=
{'a','b','c'}
for
i=1,#array
do
print(
array[i]
)
end