{"id":854,"date":"2019-12-17T17:11:24","date_gmt":"2019-12-17T09:11:24","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=854"},"modified":"2020-09-27T17:05:31","modified_gmt":"2020-09-27T09:05:31","slug":"unity2018-4-14-tolualuatable%e5%af%bc%e8%87%b4unitycrash","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=854","title":{"rendered":"Unity2018.4.14 toLua+LuaTable\u5bfc\u81f4UnityCrash"},"content":{"rendered":"\n<p>id:41402<\/p>\n\n\n\n<p>Lua\u4e2d\u6784\u5efa\u4e86\u4e00\u4e2a\u8868<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>local displayBuildIds = {}\nlocal buildIds = config.City_Building\nfor i = 1,#buildIds do \n    table.insert(displayBuildIds, buildIds[i])\nend \nFire(\"UpdateCityGroupInfo\",displayBuildIds)\n\n\nC#\u4e2d\u83b7\u5f97\u6b64\u8868\u540e\uff1a\n\nLuaInterface.LuaTable buildIds = arg as LuaInterface.LuaTable;\nvar ids = buildIds.ToArray (); \/\/ \u5728\u6b64\u5904Crash\uff01\n\n\n\n\u9644:LuaTable.ToArray\npublic object[] ToArray()\n{\nint oldTop = luaState.LuaGetTop();\ntry\n{\n    luaState.Push(this);\n    int len = luaState.LuaObjLen(-1);\n    List&lt;object> list = new List&lt;object>(len + 1);\n    int index = 1;\n    object obj = null;\n    while(index &lt;= len)\n    {\n        luaState.LuaRawGetI(-1, index++);\n        obj = luaState.ToVariant(-1);\n        luaState.LuaPop(1);\n        list.Add(obj);\n    }                \n    luaState.LuaSetTop(oldTop);\n    return list.ToArray();\n}\ncatch (Exception e)\n{\n    luaState.LuaSetTop(oldTop);\n    throw e;\n}\n}\n<\/code><\/pre>\n\n\n\n<p>\u540e\u6539\u6210\u4f20string\u89e3\u51b3\u6b64\u95ee\u9898<\/p>\n","protected":false},"excerpt":{"rendered":"<p>id:41402 Lua\u4e2d\u6784\u5efa\u4e86\u4e00\u4e2a\u8868 \u540e\u6539\u6210\u4f20string\u89e3\u51b3\u6b64\u95ee\u9898<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/854"}],"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=854"}],"version-history":[{"count":3,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/854\/revisions"}],"predecessor-version":[{"id":857,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/854\/revisions\/857"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}