1
table.concat (table [, sep [, start [, end]]]):concat是concatenate(連鎖, 連線)的縮寫. table.concat()函式列出引數中指定table的陣列部分從start位置到end位置的所有元素, 元素間以指定的分隔符(sep)隔開。
2table.insert (table, [pos,] value):在table的陣列部分指定位置(pos)插入值為value的乙個元素. pos引數可選, 預設為陣列部分末尾.
3table.maxn (table)指定table中所有正數key值中最大的key值. 如果不存在key值為正數的元素, 則返回0。(lua5.2之後該方法已經不存在了,本文使用了自定義函式實現)
4table.remove (table [, pos])返回table陣列部分位於pos位置的元素. 其後的元素會被前移. pos引數可選, 預設為table長度, 即從最後乙個元素刪起。
5table.sort (table [, comp])對給定的table進行公升序排序。
abs取絕對值
math.abs(-15)
acos
反余弦函式
math.acos(0.5)
1.04719755
asin
反正弦函式
math.asin(0.5)
0.52359877
atan2
x / y的反正切值
math.atan2(90.0, 45.0)
1.10714871
atan
反正切函式
math.atan(0.5)
0.463647609
ceil
不小於x的最大整數
math.ceil(5.8)
cosh
雙曲線余弦函式
math.cosh(0.5)
1.276259652
cos余弦函式
math.cos(0.5)
0.87758256
deg弧度轉角度
math.deg(math.pi)
exp計算以e為底x次方值
math.exp(2)
2.718281828
floor
不大於x的最大整數
math.floor(5.6)
fmod (mod)
取模運算
math.mod(14, 5)
frexp
把雙精度數val分解為數字部分(尾數)和以2為底的指數n,即val=x*2n
math.frexp(10.0)
0.625 4
ldexp
計算value * 2的n次方
math.ldexp(10.0, 3)
80 = 10 * (2 ^3)
log10
計算以10為基數的對數
math.log10(100)
log計算乙個數字的自然對數
math.log(2.71)
0.9969
max取得引數中最大值
math.max(2.71, 100, -98, 23)
min取得引數中最小值
math.min(2.71, 100, -98, 23)
-98modf
把數分為整數和小數
math.modf(15.98)
15 98
pow得到x的y次方
math.pow(2, 5)
rad角度轉弧度
math.rad(180)
3.14159265358
random
獲取隨機數
math.random(1, 100)
math.random(100)
獲取1-100的隨機數
randomseed
設定隨機數種子
math.randomseed(os.time())
在使用math.random函式之前必須使用此函式設定隨機數種子
sinh
雙曲線正弦函式
math.sinh(0.5)
0.5210953
sin正弦函式
math.sin(math.rad(30))
0.5sqrt
開平方函式
math.sqrt(16)
tanh
雙曲線正切函式
math.tanh(0.5)
0.46211715
tan正切函式
math.tan(0.5)
0.5463024
lua table 的操作 四
table在前面作過介紹,它是一種關聯陣列,這種關聯指的是可以設定各類型別的key來儲存值。為 table a 並設定元素,然後將 a 賦值給 b,則 a 與 b 都指向同乙個記憶體位址 如果 a 設定為 nil 則 b 同樣能訪問 table 的元素。如果沒有指定的變數指向a,lua的垃圾 機制會...
lua table操作例項詳解
lua gettable lua getglobal l,mytable push mytable lua pushnumber l,1 push key 1 lua gettable l,2 pop key 1,push mytable 1 lua settable lua getglobal l...
Lua Table介紹與基礎操作
table是lua的一種資料結構用來幫助我們建立不同的資料型別 可以用任意型別的值來作陣列的索引,但這個值不能是 nil。不固定大小的,你可以根據自己需要進行擴容。table常用操作 構造器是建立和初始化表的表示式。表是lua特有的功能強大的東西。最簡單的建構函式是 用來建立乙個空表。初始化陣列 t...