Lua 學習筆記(-)

來源:互聯網
上載者:User

標籤:style   blog   os   io   使用   strong   ar   for   art   

Lua學習筆記

1、lua的優勢

  a、可擴張性     b、簡單     c、高效率     d、和平台無關


2、注釋

  a、單行注釋 --        b、多行注釋 --[[  --]]


3、類型和值   

  8個基本類型,檢測變數類型用type
  a、nil         print(type(nil))  -->nil    
     全域變數沒有賦值以前,會被預設nil類型

  b、boolean     print(type(true)) -->boolean
       除了false和nil為假,其餘都為真,所以lua中,0和Null 字元串都是真的

  c、number
     表示實數

  d、string
       1)  字串不可修改
       2)  "\" 轉義
       3)  "[[ ... ]]" 符號表示字串,可以跨行
       4)  ".." 是字串串連符, 數字之間 需要空格 避免錯誤解釋
       5)  字串和數字之間可以自動裝換 ,但是 10 == "10" 比較永遠是false, 需要使用tonumber() 將字串轉換為數字,反之用tostring()

  e、userdata

  f、function
       函數可以做參數,也可以做傳回值

  g、thread

  h、table


4、運算式

  a、算術運算子
       使用在number之間,+ - * /  包括負數符號 "-"

  b、關係運算子
     <  >  <=  >=  == ~=
     比較的時候要保證比較值之間的類型一致

  c、邏輯運算子
     and  or  not
     c = a and b   --a為false,a賦值給c,否則,將b賦值給c
     c = a or  b   --a為true, a賦值給c,否則,將b賦值給c
     not 返回true 或 false,類似 !

     and優先順序高於 or

  d、串連符
     ..

  e、運算子優先順序

  f、表的構造 {}


 5、基本文法

   a、 指派陳述式

   b、局部變數和代碼塊
       使用local 建立一個局部變數
       局部變數在 do..end內

   c、控制結構語句  

 if condition then         then-part      end;      if condition then         then-part      else         esle-part      end;      if condition then         then-part      elseif conditions then         elseif-part         ...      else         else-part      end;

 

    d、迴圈語句     

 while condition do          do-part       end;       repeat          repeat-part       until condition;       for var = exp1,exp2,exp3 do             do-part             if condition then                   break;             end;       end;       for i,v in inpairs() do               statment;       end;

 

6、函數

   a、 文法
       function func_name ( argument-list )
            statment-list
       end;

   b、返回多個值

   c、可變參數

   d、具名引數

Lua 學習筆記(-)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.