通过lua自带例子学习lua 03

-- Example 11 -- Numbers.

-- Multiple assignment showing different number formats.
-- Two dots (..) are used to concatenate strings (or a
-- string and a number).

a,b,c,d,e = 1, 1.123, 1E9, -123, .0008
print("a="..a, "b="..b, "c="..c, "d="..d, "e="..e)

 

-------- Output ------

a=1 b=1.123 c=1000000000 d=-123 e=0.0008

-- Example 12 -- More Output.

-- More writing output.

print "Hello from Lua!"
print("Hello from Lua!")

 

-------- Output ------

Hello from Lua!
Hello from Lua!

-- Example 13 -- More Output.

-- io.write writes to stdout but without new line.

io.write("Hello from Lua!")
io.write("Hello from Lua!")

-- Use an empty print to write a single new line.
print()

 

-------- Output ------

Hello from Lua!Hello from Lua!

-- Example 14 -- Tables.

-- Simple table creation.

a={} -- {} creates an empty table
b={1,2,3} -- creates a table containing numbers 1,2,3
c={"a","b","c"} -- creates a table containing strings a,b,c
print(a,b,c) -- tables don't print directly, we'll get back to this!!


-------- Output ------

table: 001EC6D0 table: 001EC7E8 table: 001EC860

-- Example 15 -- More Tables.

-- Associate index style.

address={} -- empty address
address.Street="Wyman Street"
address.StreetNumber=360
address.AptNumber="2a"
address.City="Watertown"
address.State="Vermont"
address.Country="USA"

print(address.StreetNumber, address["AptNumber"])

 

-------- Output ------

360 2a

 

posted on 2013-04-06 15:22  cv_ml_张欣男  阅读(216)  评论(0编辑  收藏  举报

导航