体验Lua

本文通过一系列示例演示了Lua语言的基本语法和特性,包括变量赋值、数据类型、流程控制及函数定义等,旨在帮助读者快速掌握Lua编程的基础知识。

想用之和NGINX结合,终结公司混乱的NGINX配置

玩起来先,感觉很精简,很实用哟。

print("hello world")
a={1,2}
b=a
print(a==b,a~=b)
a=1
b="abc"
c={}
d=print
print(_VERSION)
print(type(a))
print(type(b))
print(type(c))
print(type(d))
a="single 'quote' string and double \"quoteed\"string inside"
c=[[ multiem line
with 'single'
and "double" inside.]]
print (c)
a,b,c,d,e = 1, 2, "three", "four", 5, 6
print (a,b,c,d,e )
a, b = b, a
print ("a="..a,"b="..b,c,d,e )
print "hahahaha"
io.write("hehehe")
a={}
b={1, 2, 3}
c={"a", "b", "c"}
print (a, b, c)
address={}
address.Street = "Wyman street"
address.StreetNumber = 360
print(address.StreetNumber)
a = 1
if a == 1 then
    print("a is one")
else
    print("a is not on")
end

a = 1
while a ~= 5 do
    a = a + 1
    io.write(a.." ")
end
a = 0
repeat
    a = a + 1
    print(a)
until a == 5

for a = 1, 4 do io.write(a) end
print()
for a = 1, 6, 3 do io.write(a) end
for xm_key, xm_value in pairs({1, 3, 5, 7}) do print(xm_key, xm_value) end

a = 0
while true do
    a = a + 1
    if a == 10 then
        break
    end
end
print(a)

function myFunc(a, b, c)
    return a, b, c, "hello more", 1, true
end

a, b, c, d, e, f = myFunc(1, 2, "three")
print(a, b, c, d, e, f)

function printf(fmt, ...)
    io.write(string.format(fmt, ...))
end

printf("hello %s from %s on %s\n",
    os.getenv"USER" or "there", _VERSION, os.date())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值