Lua編程示例(四):Lua標準庫之表庫、字符串庫、系統(tǒng)庫
更新時間:2015年07月09日 10:39:04 投稿:junjie
這篇文章主要介紹了Lua編程示例(四):Lua標準庫之表庫、字符串庫、系統(tǒng)庫,需要的朋友可以參考下
tb1 = { "alpha","log","gamme"} print(table.concat(tb1," , ")) print(table.concat(tb1,"\n",nil,2)) print() tb1[88.99] = 'aaa' --返回索引值最大的值,并且計算小數(shù) print(table.maxn(tb1)) print() --默認刪除索引最大的元素并返回 print(table.remove(tb1)) print() table.insert(tb1,'3423') table.sort(tb1) print(table.concat(tb1," , ")) function sortFunc(a,b) return a>b end table.sort(tb1,sortFunc) print(table.concat(tb1," , ")) print() print(string.len("")) print(string.len("abcd")) print(string.sub("welcome",1,3)) print(string.sub("welcome",1,-1)) print(string.sub("welcome",1,-5)) print() print(os.date()) print() do local x = os.clock() local s = 0 for i=1,100000000 do s= s+i end print(string.format("the passed time is %.2f\n",os.clock()-x)) end s = "hello world" i, j = string.find(s, "hello") print(i, j) --> 1 5 print(string.sub(s, i, j)) --> hello print(string.find(s, "world")) --> 7 11 i, j = string.find(s, "l") print(i, j) --> 3 3 print(string.find(s, "lll")) --> nil s = string.gsub("Lua is super", "is","makes") print(s) s = string.gsub(s,"a","X") print(s) s = string.gsub(s,"X","a",1) print(s)
運行結果:
alpha , log , gamme alpha log 88.99 gamme 3423 , alpha , log log , alpha , 3423 0 4 wel welcome wel 11/24/11 17:55:44 the passed time is 2.12 1 5 hello 7 11 3 3 nil Lua makes super LuX mXkes super Lua mXkes super
相關文章
使用lua實現(xiàn)php的var_dump()函數(shù)功能
小編比較熟悉php,所以這篇文章主要介紹了使用lua實現(xiàn)php的var_dump()函數(shù)功能,需要的朋友可以參考下2014-11-11lua中使用packagepath解決多個項目的路徑?jīng)_突問題
這篇文章主要介紹了lua中使用packagepath解決多個項目的路徑?jīng)_突問題,本文描述了問題的產(chǎn)生環(huán)境和原因,并給出了解決方法,需要的朋友可以參考下2015-04-04Openresty服務器使用lua腳本寫的Hello World簡單實例
這篇文章主要介紹了Openresty服務器使用lua腳本寫的Hello World簡單實例,OpenResty (也稱為 ngx_openresty)是一個全功能的 Web 應用服務器。它打包了標準的 Nginx 核心,很多的常用的第三方模塊,以及它們的大多數(shù)依賴項,需要的朋友可以參考下2015-04-04