欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Lua腳本語言基本語法快速入門教程

 更新時(shí)間:2015年07月09日 09:40:23   投稿:junjie  
這篇文章主要介紹了Lua腳本語言基本語法快速入門教程,本文是一個(gè)簡(jiǎn)易教程,快速的羅列了常用語法,有一定編程語言基礎(chǔ)的同學(xué)更容易看芯片,需要的朋友可以參考下

Lua語法與C語言有些相似也不太一樣,寫了語句學(xué)一下 微笑

--begin
a = --[[explain]] "ha";
print(a)

if a == "ha" then
 print("if test passed")
else
 print("if used wrong")
end

b,c=2,3
print(b,c)
b,c=c,b
if b==3 and c==2 then
 print("swap test passed")
 print(b,c)
else
 print("swap error")
end

do
 b = 6
 if b==6 then
 print("code block test passed")
 else
 print("code block test error")
 end
end

do
 d=true;
 local e="haha"
end
if d==true and e==nil then
 print("local test passed")
else
 print("local test error")
end

c = 2^3
if c == 8 then
 print("squert test passed")
else
 print("test error")
end

a = "string will be ".."connected"
print(a)

x = x or a --if not x then x = v end
print(x)


print(type(asdf))

c=3-1.2;
print(c)

d = [[
怎么會(huì)
 怎么會(huì)
 你竟原諒了我?

]]
print(d)

function test (w)
 print("the num is "..w)
 local add=w+1
 return add;
end

b=test(5)
print(add,b)


t={
 100,
 [100] = "I'm the 100th element",
 fsy=
 {
 ['age']=22,
 sex = "male", --如果是字符串,可以去掉引號(hào)和括號(hào)
 },--元素之間必須用,隔開
 20, -- 相當(dāng)于t[2]=20
}

print(t[0])
print(t[1])
print(t[100])
print(t.fsy.age)
print(t[2])

g = {
 age = 3,
 add=function (s,n) s.age=s.age+n end
}

g:add(10) --相當(dāng)于g.add(g,10)
print(g.age)

運(yùn)行的結(jié)果如下:

>lua -e "io.stdout:setvbuf 'no'" "hello.lua" 
ha
if test passed
2 3
swap test passed
3 2
code block test passed
local test passed
squert test passed
string will be connected
string will be connected
nil
1.8
怎么會(huì)
 怎么會(huì)
 你竟原諒了我?


the num is 5
nil 6
nil
100
I'm the 100th element
22
20
13
>Exit code: 0


相關(guān)文章

最新評(píng)論