Lua数据类型

Lua基础练习

print("\n======session 1======")

print(type("hello world"))
print(type(print))
print(type(nil))
print(type(true))
print(type(360.0))

print("\n======session 2======")

local a = true
local b = 0
local c = nil
local d = false

if a then
    print("a")
else
    print("not a")
end

if b then
    print("b")
else
    print("not b")
end

if c then
    print("c")
else
    print("not c, c is nil")
end

if d then
    print("d")
else
    print("not d, d is false")
end

print("\n======session 3======")

local order = 3.99
local score = 98.01

print(math.floor(order))
print(math.ceil(score))
print(9223372036854775807LL - 1)

print("\n======session 4======")

print("hello world")
print("hello lua")
print([[add\name, world]])
print([==[hello with [][[]]]==])

print("\n======session 5======")

local crop = {
    web = "google.com",
    phone = "911",
    staff = {"jack", "tom", "jim"},
    10882,
    99834,
    [10] = 360,
    ["key"] = "value"
}

print([[local crop = {
    web = "google.com",
    phone = "911",
    staff = {"jack", "tom", "jim"},
    10882 = "hello",
    99834 = "world",
    [10] = 360,
    ["key"] = "value"
}]])

print(crop.web)
print(crop["phone"])
print(crop.staff[1])
print(crop[1])
print(crop[2])
print(crop.key)
print(crop["10"])

print("\n======session 6======")

local function foo()
    print("in function")
    local a = 10
    local b = 20
    return a + b
end

local a = foo

print(a())