<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Lua基礎數據類型 函數type能夠返回一個值或一個變量所屬的類型。 ~~~ print(type("hello world")) -->output:string print(type(print)) -->output:function print(type(true)) -->output:boolean print(type(360.0)) -->output:number print(type(nil)) -->output:nil ~~~ #### nil(空) nil是一種類型,Lua將nil用于表示“無效值”。一個變量在第一次賦值前的默認值是nil,將nil賦予給一個全局變量就等同于刪除它。 ~~~ local num print(num) -->output:nil num = 100 print(num) -->output:100 ~~~ #### boolean(布爾) 布爾類型,可選值true/false;Lua中nil和false為“假”,其它所有值均為“真”。 ~~~ local a = true local b = 0 local c = nil if a then print("a") -->output:a else print("not a") --這個沒有執行 end if b then print("b") -->output:b else print("not b") --這個沒有執行 end if c then print("c") --這個沒有執行 else print("not c") -->output:not c end ~~~ #### number(數字) number類型用于表示實數,和c/c++里面的double類型一樣。可以使用數學函數math.floor(向下取整)和math.ceil(向上取整)進行取整操作。 ~~~ local order = 3.0 local score = 98.5 print(math.floor(order)) -->output:3 print(math.ceil(score)) -->output:99 ~~~ #### string(字符串) Lua中有三種方式表示字符串: 1、使用一對匹配的單引號。例:'hello'。 2、使用一對匹配的雙引號。例:"abclua"。 3、字符串還可以用一種長括號(即[[ ]])括起來的方式定義。 我們把兩個正的方括號(即[[ )間插入 n 個等號定義為第 n 級正長括號。 就是說,0 級正的長括號寫作 [[ , 一級正的長括號寫作 [=[ ,如此等等。 反的長括號也作類似定義; 舉個例子,4 級反的長括號寫作 ]====] 。 一個長字符串可以由任何一級的正的長括號開始,而由第一個碰到的同級反的長括號結束。 整個詞法分析過程將不受分行限制,不處理任何轉義符,并且忽略掉任何不同級別的長括號。 這種方式描述的字符串可以包含任何東西,當然本級別的反長括號除外。 例:[[abc\nbc]],里面的"\n"不會被轉義。 另外,Lua的字符串是不可改變的值,不能像在c語言中那樣直接修改字符串的某個字符,而是根據修改要求來創建一個新的字符串。Lua也不能通過下標來訪問字符串的某個字符。想了解更多關于字符串的操作,請查看[String庫](#)章節。 ~~~ local str1 = 'hello world' local str2 = "hello lua" local str3 = [["add\name",'hello']] local str4 = [=[string have a [[]].]=] print(str1) -->output:hello world print(str2) -->output:hello lua print(str3) -->output:"add\name",'hello' print(str4) -->output:string have a [[]]. ~~~ #### table(表) table類型實現了“關聯數組”。“關聯數組” 是一種具有特殊索引方式的數組,索引可為字符串string或(整)數number類型。 ~~~ local corp = { web = "www.google.com", --索引為字符串,key = "web", value = "www.google.com" telephone = "12345678", --索引為字符串 staff = {"Jack", "Scott", "Gary"}, --索引為字符串,值也是一個表 100876, --相當于 [1] = 100876,此時索引為數字,key = 1, value = 100876 100191, --相當于 [2] = 100191,此時索引為數字 [10] = 360, --直接把數字索引給出 ["city"] = "Beijing" --索引為字符串 } print(corp.web) -->output:www.google.com print(corp["telephone"]) -->output:12345678 print(corp[2]) -->output:100191 print(corp["city"]) -->output:"Beijing" print(corp.staff[1]) -->output:Jack print(corp[10]) -->output:360 ~~~ 想了解更多關于table的操作,請查看[Table庫](#)章節。 #### function(函數) 在Lua中,**函數** 也是一種數據類型,函數可以存儲在變量中,可以通過參數傳遞給其他函數,還可以作為其他函數的返回值。 > 示例 ~~~ function foo() print("in the function") --dosomething() local x = 10 local y = 20 return x + y end local a = foo --把函數賦給變量 print(a()) --output: in the function 30 ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看