<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## lua_pop & lua_settop ### lua_settop 我們直接來看`lua_settop`,文檔解釋 ``` /* 設置棧的高度,如果之前的棧頂比新設置的更高,那么高出來的元素會被丟棄,反之壓入nil來補足大小 假設棧里有2個元素。 如果index=0,那么移除棧上所有元素 如果index=1,移除棧頂一個元素 如果index=4,那么壓入2個nil元素 */ void lua_settop (lua_State *L, int index); ``` 使用代碼測試 ```c int lua_test(lua_State *L) { int pop_num = lua_tointeger(L,1); printf("pop_num= %d\n", pop_num); lua_settop(L,0); printf("1-top %d\r\n",lua_gettop(L)); lua_pushinteger(L,31); lua_pushinteger(L,32); lua_pushinteger(L,33); lua_pushinteger(L,34); printf("2-top %d\r\n",lua_gettop(L)); lua_pop(L,pop_num); lua_settop(L, -2); //清除一個棧頂 printf("3-top %d\r\n",lua_gettop(L)); printf("棧底 %d\r\n",lua_tointeger(L,1)); printf("棧頂 %d\r\n",lua_tointeger(L,-1)); return 0; } ``` 輸出 ``` pop_num= 0 1-top 0 2-top 4 3-top 3 棧底 31 棧頂 33 ``` 總結`lua_settop(L, idx)`函數 * idx=0 棧中元素全部移除 * idx>0 設置棧的高度,如果之前的棧頂比新設置的更高,那么高出來的元素會被丟棄,反之壓入nil來補足大小 * idx<0 idx=-1表示棧頂,棧不受影響;idx=-2表示清除一個棧頂元素,一次類推; ### lua_pop 從代碼里看到 ``` #define lua_pop(L,n) lua_settop(L, -(n)-1) ``` 因為`lua_pop`是`lua_settop`宏定義, lua_pop(L,num)函數表示從棧頂開始移除。 * 當num>0時從棧頂移除指定個數 。 * 當num=0時棧不受影響 * 當num<0,當num=-1時棧中元素全部移除; num=-2表示清除一個棧頂元素,一次類推; * 但是負數編號不能超出棧底的負數索引,超出會拋出異常 ## bc ``` /** * 把給定索引處的 Lua 值轉換為 lua_Integer 這樣一個有符號整數類型 * 必須:數字/字符串類型數字 */ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) * idx = -1代表棧頂 * idx = 1 代表棧底 /** * 返回LUA 棧的個數 * 同時也是棧頂元素的索引,因為棧底是1 */ LUA_API int lua_gettop (lua_State *L) ``` 參考鏈接:http://www.daileinote.com/computer/lua/17
                  <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>

                              哎呀哎呀视频在线观看