{"id":6510,"date":"2026-08-12T19:10:44","date_gmt":"2026-08-12T11:10:44","guid":{"rendered":"https:\/\/blog.coolcoding.cn\/?p=6510"},"modified":"2026-08-12T19:10:44","modified_gmt":"2026-08-12T11:10:44","slug":"%e5%85%b3%e4%ba%8elua-stack%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=6510","title":{"rendered":"\u5173\u4e8eLua Stack\u7684\u95ee\u9898"},"content":{"rendered":"\n<p>\u95ee\u9898<\/p>\n\n\n\n<p>\u5728Lua\u4e2d\u8c03\u7528\u4e00\u4e2aC\u51fd\u6570\uff0c\u6b64C\u51fd\u6570\u9700\u8981\u8fd4\u56de\u4e00\u6279(>1000\u4e2a)\u6574\u6570\u6570\u503c<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u65b9\u6cd51 &#8211; \u76f4\u63a5\u538b\u6808\u5904\u7406<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>static int lua_get_valus(lua_State* L)\r\n{\r\n  for(int i=0; i&lt;1000; ++i)\r\n  {\r\n    lua_pushinteger(L, i);\r\n  }   \r\n  return 1000;\r\n}<\/code><\/pre>\n\n\n\n<p>\u8868\u73b0\uff1a<strong>\u4f1a\u5bfc\u81f4lua\u6808\u6ea2\u51fa\uff0c\u5185\u5b58\u5404\u79cd\u5f02\u5e38\u3002<\/strong><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u65b9\u6cd52 &#8211; \u6808\u6269\u5bb9<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>static int lua_get_valus(lua_State* L)\n{\n  lua_checkstack(L, 1000); \/\/ \u6269\u5bb9\uff0c\u4e0d\u5d29\u4e86\n  for(int i=0; i&lt;1000; ++i)\n  {\n    lua_pushinteger(L, i);\n  }   \n  return 1000;\n}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u65b9\u6cd53 &#8211; \u7528Table\u4f20\u9012<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>lua_newtable(L);\nauto tp = lua_gettop(m_L);\nfor(int i=0; i&lt;1000; ++i)\n{\n  lua_pushnumber(L, i);\n  lua_rawseti(L, tp, nextIdx+1);\n}\nreturn 1<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898 \u5728Lua\u4e2d\u8c03\u7528\u4e00\u4e2aC\u51fd\u6570\uff0c\u6b64C\u51fd\u6570\u9700\u8981\u8fd4\u56de\u4e00\u6279(>1000\u4e2a)\u6574\u6570\u6570\u503c \u65b9\u6cd51 &#8211; \u76f4\u63a5\u538b\u6808 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/6510"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6510"}],"version-history":[{"count":4,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/6510\/revisions"}],"predecessor-version":[{"id":6514,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/6510\/revisions\/6514"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}