lua快速入门

1.万年不变 hello world
print("hello world")

2.lua的数据类型

print(type("Hello world"))        --> string
    print(type(10.4*3))               --> number
    print(type(print))                --> function
    print(type(type))                 --> function
    print(type(true))                 --> boolean
    print(type(nil))                  --> nil
    print(type(type({})))             --> table

3.if语句

if false or nil then
    print("one true")
else
    print("all false")
end

-->output:
    all false

4.字符串定义

string1 = "hello"
string2 = 'world'

html = [[
<html>
<body>
    hello world
</body>
</html>
]]
print(html)

str = string1.." "..string2
print(str)  -->hello world
print("3"+5) -->8
print(#str) -->11

5.table(表)

tab1={}
a = {"apple","pear"}
a["key"]="orange"
key = 10
a[key]=22
a[key]=a[key]+11

for k,v in pairs(a) do
    print(k..":"..v)
end

print("--")
for i=1,4 do
    print(a[i])
end

-->output:
1:apple
2:pear
key:orange
10:33
--
apple
pear
nil
nil

6.function

function factorial(n,fun)
    if( n==0) then
        return 1
    else
        return n*factorial(n-1)
    end
end

foo = factorial
print(foo(5))

-->output:
120
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值