{"id":5602,"date":"2024-03-20T10:01:16","date_gmt":"2024-03-20T02:01:16","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=5602"},"modified":"2024-03-20T10:05:39","modified_gmt":"2024-03-20T02:05:39","slug":"lua%e7%9a%84%e8%af%ad%e6%b3%95%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=5602","title":{"rendered":"lua\u7684\u8bed\u6cd5\u95ee\u9898\uff1awrong number of arguments to &#8216;insert&#8217;"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>-- \u8bed\u53e51\nlocal item = getItem()\ntable.insert(list, item)\n\n-- \u8bed\u53e52\ntable.insert(list, getItem())<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0a2\u4e2a\u8bed\u53e5\uff0c\u4e00\u822c\u6765\u8bf4\uff0c\u8bed\u53e52\u53ef\u4ee5\u76f4\u63a5\u66ff\u4ee3\u8bed\u53e51\uff0c\u4f46\u662f<strong>\u4ed6\u4eec\u662f\u4e0d\u7b49\u4ef7\u7684<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>local function getItem()\n  ..\n  return\nend<\/code><\/pre>\n\n\n\n<p>\u5982\u679cgetItem\u7684\u8fd4\u56de\u503c\u662freturn\u6216\u8005\u6ca1\u5199\uff0c\u8bed\u53e52\u5c31\u4f1a\u51fa\u9519<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wrong number of arguments to 'insert'\nstack traceback:<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3ainsert\u662f\u8fd9\u6837\u5199\u7684<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static int tinsert (lua_State *L) {\n  int e = aux_getn(L, 1) + 1;  \/* first empty element *\/\n  int pos;  \/* where to insert new element *\/\n  int c = lua_gettop(L);\n  switch (c) {\n    case 2: {  \/* called with only 2 arguments *\/\n      pos = e;  \/* insert new element at the end *\/\n      break;\n    }\n    case 3: {\n      pos = luaL_checkint(L, 2);  \/* 2nd argument is the position *\/\n      ...\n      break;\n    }\n    default: {\n      return luaL_error(L, \"wrong number of arguments to \" LUA_QL(\"insert\"));\n    }\n...<\/code><\/pre>\n\n\n\n<p>\u6240\u4ee5\u5f53getItem\u6ca1\u6709\u8fd4\u56de\u503c\u65f6\uff0c\u6808\u91cc\u53c2\u6570\u4e2a\u6570\u7b49\u4e8e1\uff08\u5373list\uff09<br>table.insert(list, getItem())\u7684\u8c03\u7528\u7b49\u540c\u4e8e table.insert(list)\uff0c\u5373\u53d1\u751fwrong number of arguments to\u9519\u8bef<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u4e0a2\u4e2a\u8bed\u53e5\uff0c\u4e00\u822c\u6765\u8bf4\uff0c\u8bed\u53e52\u53ef\u4ee5\u76f4\u63a5\u66ff\u4ee3\u8bed\u53e51\uff0c\u4f46\u662f\u4ed6\u4eec\u662f\u4e0d\u7b49\u4ef7\u7684 \u5982\u679cgetItem\u7684\u8fd4\u56de\u503c\u662freturn [&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\/5602"}],"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=5602"}],"version-history":[{"count":3,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5602\/revisions"}],"predecessor-version":[{"id":5606,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5602\/revisions\/5606"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}