最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

【無廢話30分鐘】Lua快速入門教程 - 4K超清

2022-09-16 20:31 作者:馬芮  | 我要投稿

鏈接:

筆記——無廢話30分鐘 Lua快速入門教程 - MR牛仔的文章 - 知乎

https://zhuanlan.zhihu.com/p/565192600


-- https://wiki.luatos.com/
-- http://www.lua.org/manual/

print("Hello World!")

a = 1       -- global variable
local b = 2 -- local variable
c, d, e, f, g = 3, 4, 5, 6 -- structure binding


print(g, h) -- nil

-- type: number
a = 0x1A
b = 3.14e10


a = 7
b = 5
print("+", a + b)
print("-", a - b)
print("*", a * b)
print("/",a / b)
print("//", a // b)
print("%", a % b)
print("^", a ^ b)
print("<<", 1 << 3)
print(">>", 8 >> 3)

-- type: string
print("--------------------------------- string")
local name1 = "abc \n abc"
local name2 = 'def'


local name3 = [[
line2\n
line3]]
print("[[]]", name3) -- 轉(zhuǎn)義字符在這里不起作用

local name4 = name1..name2


local str = tostring(456)


local num = tonumber("789")
local failed = tonumber("123abc") -- nil


local length = #str


-- function
print("--------------------------------- function")
function fun(x, y)
    print("x:", x, "y:", y)
end
fun(314, 3.14)
fun(255) -- y:nil
local ret = fun()
print(ret) -- nil


fun2 = function(a, b)
    return a, b
end


a, b = fun2(314, 3.14)


-- 數(shù)組
print("--------------------------------- table number_index")
tab = {1, 2, 3, 4, 5, 6, 7, 8, 9, "ac", {}, function() end}
print(tab[1]) -- starts from 1

print(tab[100]) -- nil
tab[100] = 123 -- add new


local length_of_tab = #tab -- length

table.insert(tab, "insert to tail")
table.insert(tab, 2, "insert to second")

local removed = table.remove(tab, 1)


print("--------------------------------- table string_index")
person = {
    name = "Cherno",
    age = 24,
    gender = "male",
    [",;:$"] = "bad variable name" -- bad name
}
print(person.name)

print(person["gender"])
print(person[",;:$"])

person["mom"] = "Cherno's mom" -- add new
print(person["pap"]) -- nil



-- 全局表
print("--------------------------------- _G")
print(_G)

global_variable = "global_variable"
local local_variable = "local_variable"
print(_G["global_variable"])
print(_G["local_variable"]) -- nil

-- table.insert
print(_G["table"])
print(_G["table"]["insert"])



-- 真假
print("--------------------------------- true & false")
local T = true  -- 0 and anything but nil, false
local F = false -- nil, false

print(">", 1>2)
print(">=", 1>=2)
print("<", 1<2)
print("<=", 1<=2)
print("==", 1==2)
print("~=", 1~=2)


T = 0
F = nil
print(T and F) -- 返回某一個(gè)操作數(shù)的值,而不是常規(guī)意義的布爾值
print(T or F)
print(not T)

print(T > 0 and "YES" or "NO")

print("--------------------------------- if")
if F then
    print(false)
elseif T then
    print(true)
else
    print("Error")
end



print("--------------------------------- for")
for i = 1, 10 do
    print(i)
end


for i = 1, 10, 2 do
    print(i)
end


for i = 10, 1, -1 do
    print(i)
end


for i = 1, 10 do
    local i = 4766
    print(i)
end


for i = 1, 10 do
    print(i)
    if i == 5 then break end
end



print("--------------------------------- while")
local it = 10
while it > 1 do
    print(it)
    it = it - 1
    if(it == 5) then break end
end


print("--------------------------------- Appendix")
local string_char = string.char(0x30, 0x31, 0x32, 0x33, 0x00) -- 0x00 ok
local askii_code = string.byte(string_char, 1)


【無廢話30分鐘】Lua快速入門教程 - 4K超清的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
水富县| 汽车| 清流县| 吕梁市| 图木舒克市| 郸城县| 越西县| 泗水县| 微博| 江都市| 荣昌县| 滨海县| 平顶山市| 济源市| 双峰县| 大理市| 中山市| 井研县| 阳东县| 华容县| 平顶山市| 台中县| 锦州市| 张北县| 绥棱县| 潞城市| 英吉沙县| 霍林郭勒市| 新巴尔虎右旗| 辽阳市| 裕民县| 定边县| 新野县| 黑山县| 长兴县| 新和县| 马关县| 泽普县| 凤山市| 阜康市| 平塘县|