{"id":1298,"date":"2018-05-29T17:32:10","date_gmt":"2018-05-29T09:32:10","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=1298"},"modified":"2018-05-29T17:32:10","modified_gmt":"2018-05-29T09:32:10","slug":"lua-c-api-%e7%9a%84%e6%ad%a3%e7%a1%ae%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/1298","title":{"rendered":"Lua C API \u7684\u6b63\u786e\u7528\u6cd5"},"content":{"rendered":"<div id=\"entry-962\" class=\"entry\">\n<h3 class=\"entry-header\">Lua C API \u7684\u6b63\u786e\u7528\u6cd5<\/h3>\n<div class=\"entry-content\">\n<div class=\"entry-body\">\n<p>Lua \u4f5c\u4e3a\u4e00\u95e8\u5d4c\u5165\u5f0f\u8bed\u8a00\uff0c\u63d0\u4f9b\u4e86\u5b8c\u5907\u7684 C API \u4f9b Lua \u4ee3\u7801\u548c\u5bbf\u4e3b\u7a0b\u5e8f\u4ea4\u4e92\uff0c\u5f53\u7136\uff0c\u5bbf\u4e3b\u8bed\u8a00\u6700\u597d\u662f C \u6216 C++ \u3002\u5982\u679c\u662f\u5176\u5b83\u8bed\u8a00\uff0c\u6bd4\u5982\u6700\u8fd1\u4e24\u5e74\u6d41\u884c\u7684\u5728 mono \u73af\u5883\u5d4c\u5165 Lua \u53e6\u5f53\u522b\u8bba\u3002<\/p>\n<p>\u6b63\u786e\u5c06 Lua \u5d4c\u5165\u662f\u4e0d\u592a\u5bb9\u6613\u505a\u5bf9\u7684\u4e8b\u60c5\uff0c\u5f88\u591a\u521a\u63a5\u89e6 Lua \u7684\u4eba\u90fd\u5bb9\u6613\u72af\u9519\u8bef\u3002\u597d\u5728\u505a\u8fd9\u79cd\u8bed\u8a00\u6865\u63a5\u5de5\u4f5c\u90fd\u662f\u9879\u76ee\u5f00\u59cb\u9636\u6bb5\u7684\u8bbe\u8ba1\u8005\u505a\u7684\uff0c\u4e0d\u5fc5\u4eba\u4eba\u5b66\u4f1a\uff0c\u6240\u4ee5\u53ea\u8981\u6709\u719f\u6089 Lua \u7684\u4eba\u6765\u641e\uff0c\u72af\u9519\u8bef\u7684\u5371\u5bb3\u4e0d\u4f1a\u592a\u5927\u3002\u800c\u4e14\u5373\u4f7f\u505a\u7684\u6709\u95ee\u9898\uff0c\u65e5\u540e\u4fee\u6539\u4e5f\u6bd4\u8f83\u5bb9\u6613\u3002\u8fd9\u7bc7 blog \u4e3b\u8981\u5c31\u662f\u8c08\u8c08\uff0c\u6700\u5bb9\u6613\u505a\u9519\u7684\u4f4d\u7f6e\uff0c\u548c\u4e00\u4e9b\u6b63\u786e\uff08\u4f46\u770b\u8d77\u6765\u9ebb\u70e6\uff09\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n<p>\u6700\u5bb9\u6613\u5ffd\u7565\u7684\u662f Lua \u4e2d error \u7684\u5904\u7406\u3002<\/p>\n<p>Lua \u4e2d\u53eb error \uff0c\u518d\u5176\u5b83\u8bed\u8a00\u4e2d\u53eb exception \uff0c\u540e\u9762\u59d1\u4e14\u5168\u90e8\u79f0\u4e3a\u5f02\u5e38\u5427\u3002<\/p>\n<p>\u5982\u679c\u4f60\u8ba4\u771f\u8bfb\u8fc7\u00a0<a href=\"http:\/\/www.lua.org\/manual\/5.3\/manual.html\">Lua \u7684\u624b\u518c<\/a>\u3002 \u5c31\u4f1a\u53d1\u73b0\uff0c\u5728\u6240\u6709 C API \u90a3\u91cc\uff0c\u90fd\u6ce8\u660e\u4e86\u8fd9\u4e2a API \u662f\u5426\u4f1a\u629b\u51fa\u5f02\u5e38\u3002\u6bd4\u65b9\u8bf4\u00a0<code>lua_tostring<\/code>\u00a0\u5c31\u6807\u6ce8\u7684\u662f\u00a0<code>[-0, +1, e]<\/code>\u00a0\uff0c\u6709\u53ef\u80fd\u629b\u51fa\u5f02\u5e38\uff08\u662f\u4e0d\u662f\u548c\u4f60\u7684\u76f4\u89c9\u4e0d\u540c\uff1f\uff09\uff1b\u4f46\u00a0<code>lua_pushlightuserdata<\/code>\u00a0\u5219\u4e0d\u4f1a\u3002<\/p>\n<p>Lua \u7684\u5f02\u5e38\u5e94\u8be5\u7531\u00a0<code>lua_pcall<\/code>\u00a0\u6216\u00a0<code>lua_resume<\/code>\u00a0\u6765\u6355\u83b7\uff0c\u6240\u4ee5\u5f53\u4f60\u8c03\u7528 C API \u7684\u65f6\u5019\uff0c\u5e94\u8be5\u786e\u4fdd\u5728 C \u7684\u8c03\u7528\u5c42\u6b21\u4e0a\uff0c\u5904\u4e8e\u67d0\u6b21\u00a0<code>lua_pcall<\/code>\u00a0\u6216\u00a0<code>lua_resume<\/code>\u00a0\u4e2d\u3002\u6240\u4ee5\uff0c\u5373\u4f7f\u662f\u5e38\u89c1\u7684\u521b\u5efa Lua \u865a\u62df\u673a\u7684\u7b80\u5355\u51e0\u884c\u4ee3\u7801\uff0c\u90fd\u6709\u53ef\u80fd\u5199\u9519\u3002\u6bd4\u5982\uff1a<\/p>\n<pre>lua_State *L = luaL_newstate();\r\nif (L) {\r\n  luaL_openlibs(L);\r\n}\r\n<\/pre>\n<p>\u8fd9\u6837\u5199\u5c31\u662f\u8003\u8651\u4e0d\u5468\u7684\u3002\u56e0\u4e3a\u00a0<code>luaL_openlibs(L)<\/code>\u00a0\u53ef\u80fd\u629b\u51fa\u5f02\u5e38\uff0c\u8fd9\u6837\u4fbf\u6ca1\u6709\u6355\u83b7\u5b83\u3002<\/p>\n<\/div>\n<div id=\"more\" class=\"entry-more\">\n<p>\u5f53 lua \u53d1\u751f\u4e86\u672a\u6355\u83b7\u7684\u5f02\u5e38\u65f6\uff0c\u4f1a\u8c03\u7528 panic \u51fd\u6570\uff0c\u7136\u540e\u8c03\u7528 abort() \u9000\u51fa\u8fdb\u7a0b\u3002\u4e00\u4e2a\u8865\u6551\u7684\u65b9\u6cd5\u662f\u5728\u6846\u67b6\u7684\u6700\u5916\u5c42\u8bbe\u7f6e\u4e00\u4e2a\u6062\u590d\u70b9\uff1aC \u8bed\u8a00\u7528 setjmp \uff0cC++ \u7528 try catch \u3002\u5728\u00a0<code>lua_atpanic<\/code>\u00a0\u8bbe\u7f6e\u7684 panic \u65b9\u6cd5\u4e2d\uff0c\u76f4\u63a5\u8df3\u8f6c\u5230\u6062\u590d\u70b9\uff08 C \u8bed\u8a00\u7528 longjmp \uff0cC++ \u7528 throw \uff09\u8ba9 panic \u51fd\u6570\u6c38\u4e0d\u8fd4\u56de\u3002\u4f46\u8fd9\u5e76\u975e\u63a8\u8350\u7684\u624b\u6cd5\uff0c\u6309 Lua \u4f5c\u8005 Roberto \u7684\u8bf4\u6cd5\uff0c\u201cThe panic mode is only for ill-structured Lua programs.\u201d\u3002<\/p>\n<p>\u5f53\u4f60\u53ea\u7528 C \u7f16\u5199 Lua \u7684\u5e93\u65f6\uff0c\u5373\u7528\u4e00\u4e2a\u73b0\u6210\u7684\uff0c\u8003\u8651\u5b8c\u5907\u7684\u5bbf\u4e3b\u7a0b\u5e8f\uff08\u6bd4\u5982 Lua \u5b98\u65b9\u7684\u89e3\u91ca\u5668)\u65f6\uff0c\u8fd9\u4e2a\u95ee\u9898\u901a\u5e38\u4e0d\u5fc5\u8003\u8651\u3002\u56e0\u4e3a\u4f60\u8c03\u7528 Lua C API \u7684 C \u4ee3\u7801\u5757\u90fd\u662f\u76f4\u63a5\u6216\u95f4\u63a5\u88ab Lua \u8c03\u7528\u7684\u3002\u4f46\u628a Lua C API \u904d\u5e03\u5728\u5bbf\u4e3b\u7a0b\u5e8f\u4e2d\u65f6\u5374\u5f88\u5bb9\u6613\u5ffd\u89c6\u3002\u5b8c\u5584\u7684\u505a\u6cd5\u662f\uff0c\u4f60\u5e94\u8be5\u628a\u4f60\u7684\u4e1a\u52a1\u903b\u8f91\u5199\u5230\u4e00\u4e2a\u00a0<code>lua_CFunction<\/code>\u00a0\u4e2d\uff0c\u7136\u540e\u7528\u00a0<code>lua_pcall<\/code>\u00a0\u53bb\u8c03\u7528\u5b83\u3002\u800c\u8fd9\u4e2a\u4ee3\u7801\u5757\u7684\u53c2\u6570\u5219\u5e94\u8be5\u7528 void * \u901a\u8fc7\u00a0<code>lua_pushlightuserdata<\/code>\u00a0\u6765\u4f20\u9012\u3002<\/p>\n<p>\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\uff0c\u4e4b\u524d\u7248\u672c\u7684 Lua \u90fd\u63d0\u4f9b\u4e86\u4e00\u4e2a\u53eb\u00a0<code>lua_cpcall<\/code>\u00a0\u7684 C API \u7684\u7f18\u6545\u3002\u800c\u5728 Lua 5.2 \u652f\u6301\u4e86 light c function \u540e\uff0c\u5bf9\u4e8e\u65e0 upvalue \u7684 C function \u90fd\u53ef\u4ee5\u65e0\u989d\u5916\u6210\u672c\u7684\u901a\u8fc7\u00a0<code>lua_pushcfunction<\/code>\u00a0\u4f20\u5165 lua vm \uff0c\u6240\u4ee5\u5c31\u4e0d\u518d\u9700\u8981\u4e00\u4e2a\u5355\u72ec\u7684\u00a0<code>lua_cpcall<\/code>\u00a0\u4e86\u3002<\/p>\n<p>\u6700\u597d\u7684\u8303\u4f8b\u662f\u00a0<a href=\"http:\/\/www.lua.org\/source\/5.3\/lua.c.html\">Lua \u5b98\u65b9\u7684\u89e3\u91ca\u5668<\/a>\u00a0\u7684\u5b9e\u73b0\uff1a\u4f60\u73b0\u5728\u5e94\u8be5\u660e\u767d\uff0c\u4e3a\u4f55\u4e3b\u903b\u8f91\u88ab\u5199\u5728\u4e00\u4e2a\u53eb pmain \u7684\u51fd\u6570\u4e2d\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u5728 main \u91cc\u5b9e\u73b0\u4e86\u5427\u3002<\/p>\n<p>\u524d\u9762\u63d0\u5230\u00a0<code>lua_pushlightuserdata<\/code>\u00a0\u4e0d\u4f1a\u629b\u51fa\u5f02\u5e38\uff0c\u540c\u6837\u7684\u5176\u5b83\u7b80\u5355\u503c\u7c7b\u578b\uff0c<code>lua_pushboolean<\/code><code>lua_pushinteger<\/code>\u00a0\u7b49\u90fd\u4e0d\u4f1a\u3002\u8fd9\u662f\u56e0\u4e3a\u8fd9\u4e9b api \u662f\u4e0d\u68c0\u67e5 lua \u7684\u5806\u6808\u5bb9\u91cf\u7684\uff0c\u4e5f\u4e0d\u4f1a\u4e3b\u52a8\u6309\u9700\u6269\u5c55 Lua \u6808\u3002\u4e0d\u8fc7\u00a0<code>lua_pushstring<\/code>\u00a0\u8fd9\u79cd\u9700\u8981\u6784\u9020\u65b0\u5bf9\u8c61\u7684 API \u5219\u53ef\u80fd\u5f15\u53d1 OOM \uff08out of memory\uff09\u5f02\u5e38\uff0c\u9700\u8981\u7559\u610f\u3002lua \u53ea\u4fdd\u8bc1\u5728\u4ece Lua \u8fdb\u5165 C \u7684\u8fb9\u754c\u4e0a\u63d0\u4f9b\u989d\u5916\u7684\u00a0<code>LUA_MINSTACK<\/code>\u00a0\u4e2a slot \u3002\u8fd9\u4e2a\u503c\u9ed8\u8ba4\u4e3a 20 \uff0c\u4e00\u822c\u662f\u591f\u7528\u7684\u3002\u6b63\u56e0\u4e3a\u4e00\u822c\u591f\u7528\uff0c\u53cd\u800c\u5bb9\u6613\u88ab\u7f16\u5199 C \u6269\u5c55\u7684\u540c\u5b66\u5ffd\u89c6\u3002\u5c24\u5176\u662f\u5728 C \u6269\u5c55\u7684\u4ee3\u7801\u91cc\u6709 C \u5c42\u6b21\u4e0a\u7684\u9012\u5f52\u65f6\uff0c\u975e\u5e38\u5bb9\u6613\u5728\u8fb9\u754c\u60c5\u51b5\u4e0b\u6808\u6ea2\u51fa\u3002\u56e0\u4e3a Lua \u7684 stack \u5b9e\u9645\u4e0a\u53c8\u7ecf\u5e38\u7559\u51fa\u8d85\u8fc7\u00a0<code>LUA_MINSTACK<\/code>\u00a0\u7684\u7a7a\u95f4\uff0c\u8fd9\u79cd bug \u4e0d\u6613\u5bdf\u89c9\u3002\u8bb0\u4f4f\uff1a\u5982\u679c\u4f60\u5728 C \u6269\u5c55\u4e2d\u505a\u590d\u6742\u7684\u4e8b\u60c5\uff0c\u4e00\u5b9a\u8981\u8bb0\u5f97\u5728\u4f7f\u7528 lua stack \u524d\uff0c\u7528\u00a0<code>luaL_checkstack<\/code>\u00a0\u7559\u591f\u4f60\u9700\u8981\u7684\u7a7a\u95f4\u3002<\/p>\n<hr \/>\n<p>\u5728\u7528 C \u7f16\u5199 Lua \u7684 C \u6269\u5c55\u5e93\u65f6\uff0c\u7531\u4e8e C API \u6709\u629b\u51fa\u5f02\u5e38\u7684\u53ef\u80fd\uff0c\u4f60\u8fd8\u9700\u8981\u8003\u8651\uff0c\u6bcf\u6b21\u5f53\u4f60\u8c03\u7528 Lua API \u65f6\uff0c\u4e0b\u4e00\u884c\u7a0b\u5e8f\u90fd\u6709\u53ef\u80fd\u8fd0\u884c\u4e0d\u5230\u3002\u6240\u4ee5\u4e00\u65e6\u4f60\u60f3\u4e34\u65f6\u7533\u8bf7\u4e00\u4e9b\u5806\u5185\u5b58\u4f7f\u7528\uff0c\u8981\u5145\u5206\u8003\u8651\u4f60\u5728\u540c\u4e00\u51fd\u6570\u5185\u7f16\u5199\u7684\u91ca\u653e\u4e34\u65f6\u5bf9\u8c61\u7684\u4ee3\u7801\u5f88\u53ef\u80fd\u8fd0\u884c\u4e0d\u5230\u3002\u6b63\u786e\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u00a0<code>lua_newuserdata<\/code>\u00a0\u6765\u7533\u8bf7\u4e34\u65f6\u5185\u5b58\uff0c\u5982\u679c\u88ab\u5f02\u5e38\u6253\u65ad\uff0c\u540e\u7eed\u7684 gc \u6d41\u7a0b\u4f1a\u6e05\u7406\u5b83\u4eec\u3002<code>luaL_Buffer<\/code>\u00a0\u76f8\u5173\u7684\u5e93\u5c31\u662f\u57fa\u4e8e\u8fd9\u4e2a\u505a\u7684\u3002\u6216\u8005\u4f60\u81ea\u5df1\u6709\u529e\u6cd5\u901a\u8fc7\u6c60\u56de\u6536\u4e5f\u53ef\u4ee5\uff0c\u603b\u4e4b\u9700\u8981\u8003\u8651\u8fd9\u70b9\u3002<\/p>\n<p>\u57fa\u4e8e\u540c\u6837\u7684\u7406\u7531\uff0c\u5982\u679c\u4f60\u6784\u9020\u4e86\u4e00\u4e2a C \u5bf9\u8c61\uff0c\u90a3\u4e48\u5728\u8c03\u7528\u5176\u5b83 Lua C API \u4e4b\u524d\uff0c\u5e94\u8be5\u628a\u5bf9\u8c61\u4e2d\u7684\u6240\u6709\u5b57\u6bb5\u90fd\u6e05\u96f6\uff08\u8bbe\u7f6e\u6210\u5408\u6cd5\u7684\u521d\u59cb\u503c\uff09\uff0c\u907f\u514d\u901a\u8fc7 Lua C API \u4e00\u4e2a\u4e2a\u5b57\u6bb5\u8bbe\u7f6e\u3002\u6bd4\u5982\uff1a<\/p>\n<pre>struct foobar {\r\n  const char *a;\r\n  const char *b;\r\n}\r\n\r\n...\r\n\r\nstruct foobar * f = lua_newuserdata(L, sizeof(*f));\r\n\r\n... \/\/ \u4e00\u4e9b\u5176\u5b83\u5de5\u4f5c\r\n\r\nf-&gt;a = lua_tostring(L, 1);\r\nf-&gt;b = lua_tostring(L, 2);\r\n<\/pre>\n<p>\u8fd9\u6837\u5199\u5c31\u662f\u6709\u98ce\u9669\u7684\u3002\u56e0\u4e3a\uff0c\u7b2c\u4e00\u6b21\u8c03\u7528\u00a0<code>lua_tostring<\/code>\u00a0\u65f6\u6709\u53ef\u80fd\u56e0\u4e3a\u5f02\u5e38\u800c\u6267\u884c\u4e0d\u5230\u4e0b\u4e00\u884c\uff0c\u5bfc\u81f4 f-&gt;b \u6ca1\u6709\u88ab\u521d\u59cb\u5316\u3002\u6b63\u786e\u7684\u505a\u6cd5\u662f\uff1a<\/p>\n<pre>struct foobar * f = lua_newuserdata(L, sizeof(*f));\r\nf-&gt;a = NULL;\r\nf-&gt;b = NULL;\r\n\r\n... \/\/ \u4e00\u4e9b\u5176\u5b83\u5de5\u4f5c\r\n\r\nf-&gt;a = lua_tostring(L, 1);\r\nf-&gt;b = lua_tostring(L, 2);\r\n<\/pre>\n<p>\u5982\u679c\u4f60\u4ed4\u7ec6\u9605\u8bfb\u8fc7 lua \u7684\u6e90\u4ee3\u7801\uff0c\u4f1a\u53d1\u73b0 Lua \u5185\u90e8\u5b9e\u73b0\u4e2d\u4e5f\u7ecf\u5e38\u7528\u8fd9\u79cd\u60ef\u4f8b\u5199\u6cd5\u3002\u8fd9\u91cc\u4f7f\u7528 newuserdata \u53ef\u4ee5\u56de\u907f\u5927\u591a\u6570\u521d\u59cb\u5316\u5931\u8d25\u7684\u95ee\u9898\uff0c\u4f46\u4f60\u8981\u786e\u4fe1\u5728 c \u5bf9\u8c61\u6b63\u786e\u521d\u59cb\u5316\u4e4b\u540e\u624d\u80fd\u7ed9\u5c06 f \u6216\u5bf9\u5e94\u7684 lua \u5bf9\u8c61\u4f20\u9012\u5230\u522b\u5904\uff0c\u4ee5\u53ca\u7ed9 userdata \u589e\u52a0 metatable \u3002<\/p>\n<hr \/>\n<p>\u5f53\u5bbf\u4e3b\u8bed\u8a00\u672c\u8eab\u652f\u6301\u5f02\u5e38\u65f6\uff0c\u8ba9\u5bbf\u4e3b\u8bed\u8a00\u7684\u5f02\u5e38\u673a\u5236\u548c Lua \u81ea\u8eab\u7684\u5f02\u5e38\u673a\u5236\u534f\u540c\u5de5\u4f5c\u662f\u4e00\u4e2a\u96be\u9898\u3002\u60f3\u4e0d\u4fb5\u5165 Lua \u81ea\u8eab\u7684\u5b9e\u73b0\u800c\u9760\u5e93\u81ea\u8eab\u534f\u8c03\u4e24\u79cd\u5f02\u5e38\u673a\u5236\u662f\u51e0\u4e4e\u4e0d\u53ef\u80fd\u7684\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0cLua \u5141\u8bb8\u4f60\u5728\u6784\u5efa\u5e93\u7684\u65f6\u5019\u5b9a\u4e49\u4e00\u7cfb\u5217\u7684\u5b8f\u6765\u7528\u5bbf\u4e3b\u8bed\u8a00\u7684\u5f02\u5e38\u673a\u5236\u6765\u5b9e\u73b0 Lua \u7684\u5f02\u5e38\u4f20\u64ad\u3002<\/p>\n<p>\u770b\u00a0<a href=\"http:\/\/www.lua.org\/source\/5.3\/ldo.c.html\">ldo.c<\/a>\u00a0\u524d\u9762\u7684\u00a0<code>LUAI_THROW<\/code>\u00a0<code>LUAI_TRY<\/code>\u00a0\u7b49\u5b8f\u5c31\u662f\u505a\u7684\u8fd9\u4e2a\u4e8b\u60c5\u3002\u6240\u4ee5\uff0c\u5982\u679c\u4f60\u7528 C++ \u505a\u5bbf\u4e3b\u8bed\u8a00\uff0c\u5c31\u5e94\u8be5\u7528 C++ \u7f16\u8bd1\u5668\u7f16\u8bd1 Lua \u5e93\u3002\u5982\u679c\u4f60\u76f4\u63a5\u7528 C \u7f16\u8bd1\u51fa\u6765\u7684\u5e93\uff0c\u94fe\u63a5\u5230 C++ \u7a0b\u5e8f\u4e2d\uff08\u6216\u5171\u7528\u5df2\u7f16\u8bd1\u597d\u7684 lua \u52a8\u6001\u5e93\uff09\uff0c\u90a3\u4e48\u8868\u9762\u4e0a\u5de5\u4f5c\u4f1a\u4e00\u5207\u6b63\u5e38\u3002\u53ef\u4e00\u65e6\u6d89\u53ca\u5f02\u5e38\u5904\u7406\uff0c\u5c31\u4f1a\u6709\u5f88\u591a\u672a\u77e5\u7684\u95ee\u9898\u3002<\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u662f\u8fd9\u6837\u9020\u6210\u7684\uff1a<\/p>\n<p>Lua \u5728\u5185\u90e8\u53d1\u751f\u5f02\u5e38\u65f6\uff0cVM \u4f1a\u5728 C \u7684 stack frame \u4e0a\u76f4\u63a5\u8df3\u81f3\u4e4b\u524d\u8bbe\u7f6e\u7684\u6062\u590d\u70b9\uff0c\u7136\u540e unwind lua vm \u5c42\u6b21\u4e0a\u7684 lua stack \u3002lua stack \uff08CallInfo \u7ed3\u6784\uff09\u5728\u6355\u83b7\u5f02\u5e38\u540e\u662f\u6b63\u786e\u7684\uff0c\u4f46 C \u7684 stack frame \u7684\u5904\u7406\u672a\u5fc5\u5982\u4f60\u7684\u5bbf\u4e3b\u7a0b\u5e8f\u6240\u613f\u3002\u4e5f\u5c31\u662f RAII \u673a\u5236\u5f88\u53ef\u80fd\u6ca1\u6709\u88ab\u89e6\u53d1\u3002<\/p>\n<p>btw \uff0cLua \u7684 stack frame \u5e76\u4e0d\u4e00\u4e00\u5bf9\u5e94 C \u7684 stack frame \uff0c\u5373\u5e76\u4e0d\u662f\u4e00\u6b21 Lua \u5c42\u7684\u51fd\u6570\u8c03\u7528\u5c31\u5bf9\u5e94\u4e00\u5c42 C \u51fd\u6570\u8c03\u7528\uff0c\u5f53\u4f60\u5728 Lua \u5c42\u4e0a pcall \u4e00\u4e2a lua \u51fd\u6570\u4e2d\u518d pcall \u4e00\u4e2a lua \u51fd\u6570\uff0c\u4e5f\u4e0d\u662f\u76f4\u89c9\u4e0a\u7684\u505a\u4e24\u5c42 try catch \u3002Lua \u7684\u8fd9\u79cd\u5b9e\u73b0\u548c Lua \u7684\u8bed\u8a00\u7279\u6027\uff0c\u5c3e\u9012\u5f52\u4ee5\u53ca coroutine \u6709\u5173\u3002\u5982\u679c\u60f3\u5728 pcall \u7684\u5185\u90e8 coroutine.yield \u56de C \u5c42\uff0c\u5c31\u7edd\u5bf9\u4e0d\u80fd\u8ba9 Lua \u7684\u51fd\u6570\u8c03\u7528\u5bf9\u5e94\u5230 C \u51fd\u6570\u8c03\u7528\u4e0a\uff0c\u5426\u5219 coroutine \u5c31\u65e0\u6cd5 resume \uff08\u56e0\u4e3a\u5728 C \u5c42\u4e0a\u8df3\u56de\u6062\u590d\u70b9\uff0c\u5c31\u7834\u574f\u4e86 C \u5c42\u7684 stack frame \uff0c\u65e0\u6cd5\u91cd\u5efa\uff09\u3002\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u7b80\u5355\u7684\u8ba9 Lua \u5185\u90e8\u5b9e\u73b0\u7684\u5f02\u5e38\u673a\u5236\u7b80\u5355\u517c\u5bb9\u5bbf\u4e3b\u8bed\u8a00\u7684\u7f18\u6545\u3002<\/p>\n<p>\u6362\u53e5\u8bdd\u8bf4\uff0c\u5373\u4f7f\u4f60\u7528 try catch \u91cd\u65b0\u7f16\u8bd1\u4e86 lua \u5e93\u3002\u5f53\u4f60\u5728\u00a0<code>lua_pushstring<\/code>\u00a0\u8fd9\u79cd\u53ef\u80fd\u629b\u51fa\u5f02\u5e38\u7684 lua api \u5916\u4e3b\u52a8 try catch \uff0c\u8fd9\u4e2a\u5f02\u5e38\u4f60\u53ef\u4ee5\u6355\u83b7\u5230\uff08\u56e0\u4e3a\u6307\u5b9a lua vm \u7684\u5b9e\u73b0\u4e5f\u4f7f\u7528\u5b83\uff09\uff0c\u4f46\u5374\u4f1a\u7834\u574f lua vm \u672c\u8eab\u7684\u5de5\u4f5c\u3002<\/p>\n<p>\u5f3a\u8c03\uff1a\u4f60\u4e0d\u80fd\u7528 throw \u4ee3\u66ff\u00a0<code>lua_error<\/code>\u00a0\u6765\u629b\u51fa\u5f02\u5e38\uff0c\u4e5f\u4e0d\u80fd\u7528 try catch \u6765\u53d6\u4ee3\u00a0<code>lua_pcall<\/code>\u00a0\u3002\u5728 Lua VM \u5b9e\u73b0\u5c42\u9762\u6362\u6210 C++ \u7684\u5f02\u5e38\u673a\u5236\uff0c\u5e76\u4e0d\u7b49\u4e8e lua \u548c C++ \u62e5\u6709\u4e86\u7b49\u4ef7\u7684\u5f02\u5e38\u4f20\u64ad\u7cfb\u7edf\u3002\u5f53\u4f60\u660e\u767d\u6709\u4e9b lua api \u4f1a\u629b\u51fa\u5f02\u5e38\uff0c\u5e76\u4e14\u8fd9\u4e2a\u5f02\u5e38\u662f\u4ee5 C++ \u7684 throw \u629b\u51fa\u7684\uff1b\u4f60\u540c\u65f6\u4e5f\u5e94\u8be5\u660e\u767d\uff0c\u81ea\u884c\u7528 C++ \u7684\u5f02\u5e38\u6355\u83b7\u673a\u5236\u6765\u5305\u8d77\u8fd9\u4e9b lua api \u7684\u8c03\u7528\uff0c\u8bd5\u56fe\u6355\u83b7\u5f02\u5e38\u662f\u9519\u8bef\u7684\u505a\u6cd5\u3002<\/p>\n<p>\u5728 C++ \u4e2d\u5d4c\u5165 Lua \u540e\uff0c\u8ba9 C++ \u7f16\u5199\u7684\u6269\u5c55\u5e93\u6b63\u786e\u8fd0\u4f5c\u7684\u95ee\u9898\u5f88\u597d\u89e3\u51b3\uff08\u5355\u72ec\u6784\u5efa\u4e00\u4e2a C++ \u7248\u7684\u5e93\u5373\u53ef\uff09\uff0c\u4f46\u5f53\u4f60\u5728\u591a\u79cd\u8bed\u8a00\u4e2d\u4ea4\u4e92\uff0c\u4ee5 C\/C++ \u4e2d\u5a92\u4ecb\u65f6\uff0c\u8fd9\u4e2a\u95ee\u9898\u5c31\u590d\u6742\u7684\u591a\u3002\u6bd4\u5982\u8bf4\uff0c\u8fd1\u5e74\u6765\u6d41\u884c\u7528 Unity3D \u5f00\u53d1\u6e38\u620f\uff0c\u5e76\u5728 mono \u865a\u62df\u673a\u4e2d\u5d4c\u5165 Lua \u6765\u7f16\u5199\u6e38\u620f\u903b\u8f91\uff0c\u5c31\u6d89\u53ca lua mono C \u4e09\u8005\u4e4b\u95f4\u7684\u6c9f\u901a\u3002mono \u672c\u8eab\u4e5f\u6709\u81ea\u8eab\u7684\u865a\u62df\u673a\uff0c\u6050\u6015\u4f60\u5f88\u96be\u5c06 lua \u81ea\u8eab\u5b9e\u73b0\u4e2d\u7528\u5230\u7684\u00a0<code>LUAI_THROW<\/code>\u00a0<code>LUAI_TRY<\/code>\u00a0\u66ff\u6362\u4e3a mono \u7684\u5f02\u5e38\u5b9e\u73b0\u3002\u6240\u4ee5\uff0c\u5f53\u4f60\u7528 C# \u7f16\u5199\u4ee3\u7801\u8f6c\u6362\u4e3a Lua \u53ef\u4ee5\u8c03\u7528\u7684\u51fd\u6570\u65f6\uff0c\u5e94\u8be5\u907f\u514d C# \u7684\u5f02\u5e38\u6f0f\u5230 Lua \u7684 VM \u4e2d\u3002\u53cd\u8fc7\u6765\uff0clua \u5f02\u5e38\u4e5f\u4e00\u5b9a\u8981\u5728 lua \u5c42\u9762\u6216 C \u5c42\u9762\u622a\u83b7\u4f4f\u3002\u8fd9\u4e9b\u8981\u5b9e\u73b0\u7684\u975e\u5e38\u5c0f\u5fc3\uff0c\u6240\u4ee5\u4e0d\u5efa\u8bae\u76f4\u63a5\u628a lua C api \u4e00\u4e00\u6620\u5c04\u6210 C# \u51fd\u6570\uff0c\u7528 C# \u6765\u76f4\u63a5\u64cd\u4f5c lua state \uff0c\u90a3\u6837\u662f\u5f88\u96be\u5199\u7684\u5b8c\u5907\u7684\u3002<\/p>\n<p>\u8003\u8651\u5230 mono \u672c\u8eab\u5c31\u662f C \u5b9e\u73b0\u7684\uff0cLua API \u7684\u5f02\u5e38\u4f20\u64ad\u5728\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u90fd\u53ef\u4ee5\u5728 mono vm \u91cc\u6b63\u5e38\u5de5\u4f5c\uff08\u5982\u679c\u4f60\u628a mono \u4e5f\u770b\u6210\u662f C \u7f16\u5199\u7684\u6a21\u5757\u7684\u8bdd\uff09\uff0c\u4f46\u5f53\u5f02\u5e38\u53d1\u751f\u65f6\uff08Lua \u7a0b\u5e8f\u548c C \u7a0b\u5e8f\u4e0d\u4e00\u6837\uff0c\u5f88\u591a\u60c5\u51b5\u4e0b\u4f9d\u8d56\u5f02\u5e38\u4f20\u64ad\uff09\uff0c\u5373\u4f7f\u5728 Lua \u5c42\u6355\u83b7\uff0c\u53ea\u8981\u4e2d\u95f4\u7a7f\u8d8a\u4e86 C# \u4ee3\u7801\uff0c\u90a3\u4e48\u4e00\u4e9b\u526f\u4f5c\u7528\u5374\u662f\u5f88\u96be\u5bdf\u89c9\u7684\u3002\u8fd9\u662f\u56e0\u4e3a lua \u7684 VM \u5b9e\u73b0\u662f\u76f4\u63a5\u7528 longjmp \u505a C \u7684 stack frame unwind \u7684\uff0cmono vm \u5e76\u4e0d\u80fd\u611f\u77e5\u3002\u5371\u9669\u6b63\u5728\u4e8e 99% \u7684\u60c5\u51b5\u4e0b\u90fd\u5de5\u4f5c\u6b63\u5e38\uff0c\u5076\u5c14\u4e0d\u6b63\u5e38\u5374\u5f88\u96be\u53d1\u89c9\u3002<\/p>\n<p>\u5982\u679c\u5b8c\u5168\u7528 C# \u6765\u91cd\u65b0\u5b9e\u73b0\u4e00\u904d Lua \u53ef\u4ee5\u5b8c\u5907\u7684\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c<a href=\"https:\/\/github.com\/xebecnan\/UniLua\">UniLua<\/a>\u00a0\u5c31\u662f\u8fd9\u6837\u4e00\u4e2a\u9879\u76ee\u3002\u8fd9\u6837\u505a\u7684\u7f3a\u70b9\u662f\u6027\u80fd\u582a\u5fe7\u3002\u6bd5\u7adf\u540c\u6837\u7684\u4e8b\u60c5\uff0cC# \u6bd4\u539f\u751f\u4ee3\u7801\u8981\u6162\u7684\u591a\u3002<\/p>\n<p>\u5982\u679c\u4f60\u5728\u610f\u6027\u80fd\uff0c\u90a3\u4e48\u8fd8\u662f\u53ef\u4ee5\u628a Lua \u7f16\u8bd1\u6210\u539f\u751f\u5e93\uff0c\u7136\u540e\u5bfc\u51fa\u63a5\u53e3\u7ed9 C# \u4f7f\u7528\u7684\uff0c\u8fd9\u6837\u7684\u9879\u76ee\u4e5f\u5f88\u591a\uff0c\u5c31\u4e0d\u4e00\u4e00\u5217\u4e3e\u4e86\u3002\u4f46\u4f7f\u7528\u65f6\u5e94\u8be5\u6ce8\u610f\uff0c\u5e94\u8be5\u907f\u514d\u5728\u4f4e\u5c42\u6b21\u53bb\u64cd\u4f5c\u00a0<code>Lua_State<\/code>\u00a0\uff0c\u800c\u5e94\u8be5\u5c01\u88c5\u51fa\u7b80\u5355\u7684\u51e0\u4e2a\u9ad8\u5c42\u63a5\u53e3\u3002\u76f4\u63a5\u8ba9 C# \u4ee3\u7801\u53bb\u8bfb\u5199 Lua State \u4e2d\u7684\u6570\u636e\u7ed3\u6784\u5c31\u662f\u4e0d\u53ef\u53d6\u7684\u3002\u51e0\u4e4e\u6240\u6709\u7684\u5bf9 Lua State \u7684 C API \u90fd\u6709\u5f02\u5e38\u5904\u7406\u7684\u95ee\u9898\u3002\u7b80\u5355\u5c01\u88c5\u8fd9\u4e9b C API \u6210 C# \u51fd\u6570\uff0c\u8981\u4e48\u8003\u8651\u4e0d\u5b8c\u5907\u8981\u4e48\u6548\u7387\u4f4e\u4e0b\uff08\u5728\u8fc7\u4f4e\u5c42\u6b21\u4e0a\u7f16\u7801\u9020\u6210\u7684\u95ee\u9898\uff09\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u628a Lua VM \u548c mono VM \u4ea4\u4e92\u770b\u6210\u662f\u4e24\u4e2a\u9ed1\u76d2\u95f4\u7684\u4ea4\u4e92\uff0c\u5176\u5b9e\u8fd9\u548c\u4e0d\u540c\u8fdb\u7a0b\uff0c\u4e0d\u540c\u673a\u5668\uff0c\u4e0d\u540c\u670d\u52a1\u95f4\u7684\u4ea4\u4e92\u672c\u8d28\u4e0a\u5e76\u6ca1\u6709\u4ec0\u4e48\u533a\u522b\u3002\u95ee\u9898\u662f\u4e0d\u662f\u53d8\u5f97\u719f\u6089\u8d77\u6765\uff1f\u5176\u5b9e\u5c31\u662f\u76f8\u4e92\u53d1\u9001\u6d88\u606f\u7684\u8fc7\u7a0b\u3002\u6211\u4eec\u8981\u505a\u7684\u4ec5\u4ec5\u662f\u8bb2\u6d88\u606f\u7f16\u7801\uff0c\u6d88\u606f\u4f20\u9012\uff0c\u8ba9\u5bf9\u65b9\u5904\u7406\u3002\u4e0d\u8981\u8fc7\u4e8e\u8003\u8651\u6d88\u606f\u4f20\u9012\u8fc7\u7a0b\u4e2d\u7684\u6027\u80fd\u5f00\u9500\uff0c\u627f\u8ba4\u4e00\u5b9a\u7684\u5f00\u9500\uff0c\u53ef\u4ee5\u63d0\u4f9b\u66f4\u5927\u7684\u5f39\u6027\uff0c\u548c\u8bbe\u8ba1\u63a5\u53e3\u4e0a\u7684\u7b80\u6d01\u3002\u771f\u6b63\u8981\u8003\u8651\u7684\u5176\u5b9e\u662f\u600e\u4e48\u5c3d\u91cf\u51cf\u5c11\u4ea4\u4e92\u7684\u9891\u7387\u3002<\/p>\n<p>\u5176\u5b9e\u6211\u4eec\u8981\u505a\u7684\u4ec5\u4ec5\u662f\u628a C# \u51fd\u6570\u6309\u7edf\u4e00\u7684\u89c4\u683c\u6ce8\u518c\u5230 Lua VM \u4e2d\u4f9b\u5176\u8c03\u7528\uff08\u751a\u81f3\u53ea\u6709\u4e00\u4e2a\u5355\u4e00\u63a5\u53e3\u8ba9 Lua \u53d1\u9001\u6d88\u606f\u51fa\u6765\uff09\uff0c\u7ed9 C# \u63d0\u4f9b\u4e00\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u8c03\u7528 Lua \u4e2d\u7684\u51fd\u6570\uff08\u6216\u662f\u5411 Lua \u53d1\u9001\u6d88\u606f\uff0c\u7531 Lua \u4fa7\u5c06\u6d88\u606f\u8f6c\u6362\u4e3a\u51fd\u6570\u8c03\u7528\uff09\u5c31\u53ef\u4ee5\u4e86\u3002\u8003\u8651\u5230\u8fd9\u4e2a\u8fc7\u7a0b\u5176\u5b9e\u662f\u5728\u540c\u4e00\u8fdb\u7a0b\uff08\u751a\u81f3\u540c\u4e00\u7ebf\u7a0b\uff09\u4e2d\u8fdb\u884c\u7684\u3002\u6d88\u606f\u7684\u7f16\u7801\u4e0d\u4e00\u5b9a\u662f\u4e00\u4e2a\u8fde\u7eed\u7684\u5b57\u7b26\u4e32\uff0c\u53ea\u8981\u662f\u53cc\u65b9\u90fd\u53ef\u4ee5\u7f16\u7801\u89e3\u7801\u7684\u5185\u5b58\u5730\u5740\u5373\u53ef\u3002<\/p>\n<p>\u56e0\u4e3a\u5199\u8fd9\u7bc7 blog \u6b63\u662f\u6211\u4eec\u81ea\u5df1\u7684\u9879\u76ee\u9047\u5230\u4e86\u6b64\u7c7b\u9700\u6c42\uff0c\u6240\u4ee5\u6211\u5728\u5199\u6587\u5b57\u7684\u540c\u65f6\u4e5f\u4e3a\u516c\u53f8\u7684\u540c\u4e8b\u7f16\u5199\u4e86\u4e00\u7ec4\u793a\u8303\u4ee3\u7801\u3002<a href=\"https:\/\/github.com\/cloudwu\/luabind\">\u4ee3\u7801\u5728 github \u4e0a<\/a>\u00a0\u3002\u5b83\u53ea\u5b8c\u6210\u4e86\u57fa\u672c\u7684\u529f\u80fd\uff0c\u5e76\u53ea\u662f\u4e00\u4e2a C \u5e93\uff0c\u4f46\u901a\u8fc7\u4e00\u4e9b\u7b80\u5355\u7684\u5c01\u88c5\u5c31\u53ef\u4ee5\u5305\u88c5\u6210 C# \u6a21\u5757\u5728 unity3d \u7684 mono \u73af\u5883\u4e2d\u4f7f\u7528\u3002<\/p>\n<hr \/>\n<p>ps. \u672c\u6587\u63d0\u5230\u7684\u95ee\u9898\u5e76\u4e0d\u4ec5\u4ec5\u51fa\u73b0\u5728 lua \u7684\u521d\u5b66\u8005\uff0c\u4e00\u4e9b\u7528\u6237\u4f17\u591a\u7684\u5c06 lua api binding \u5230C \u4e4b\u5916\u8bed\u8a00\u7684\u5e93\u5728\u5b9e\u73b0\u7684\u65f6\u5019\u90fd\u6216\u591a\u6216\u5c11\u7684\u6709\u8fd9\u91cc\u8c08\u53ca\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4ee5 C++ \u7528\u6237\u4f7f\u7528\u8f83\u591a\u7684\u00a0<a href=\"https:\/\/github.com\/luabind\/luabind\">luabind<\/a>\u00a0\u4e3a\u4f8b\uff0c\u5b83\u6240\u63d0\u4f9b\u7684 &#8220;Lua functions in C++&#8221; \u7279\u6027\u5c31\u662f\u4e0d\u5b8c\u5907\u7684\u3002\u53ea\u662f\u8fd9\u4e2a C++ \u5e93\u5b9e\u73b0\u7684\u6781\u5176\u7e41\u6742\uff0c\u770b\u51fa\u5e76\u4e86\u89e3\u5176\u4e2d\u7684\u95ee\u9898\uff08\u8bbe\u8ba1\u7684\u5c40\u9650\u6027\uff09\u5f88\u4e0d\u5bb9\u6613\uff0c\u800c\u9690\u60a3\u53c8\u4e0d\u5bb9\u6613\u51fa\u73b0\uff0c\u5bf9\u4f7f\u7528\u8005\u6765\u8bf4\u662f\u4e2a\u5f88\u5927\u7684\u5a01\u80c1\u3002\uff08\u5f53\u7136\u4f60\u975e\u5e38\u6e05\u695a\u95ee\u9898\u540e\uff0c\u662f\u53ef\u4ee5\u4ece\u4f7f\u7528\u4e0a\u89c4\u907f\u5bb9\u6613\u51fa\u95ee\u9898\u7684\u7528\u6cd5\u7684\uff09<\/p>\n<p>\u5177\u4f53\u662f\u8fd9\u6837\uff1a\u60f3\u8ba9\u4e00\u4e2a lua \u51fd\u6570\u4ece C++ \u4e2d\u88ab\u8c03\u7528\u3002luabind \u63d0\u4f9b\u4e86\u4e00\u4e2a\u53eb\u505a\u00a0<code>call_function<\/code>\u00a0\u7684\u65b9\u6cd5\uff0c\u7528\u8d77\u6765\u5012\u662f\u7b80\u5355\uff0c<a href=\"http:\/\/www.rasterbar.com\/products\/luabind\/docs.html\">\u53c2\u770b\u5176\u6587\u6863<\/a>\u00a0\u7684 7.3 \u8282\u3002<\/p>\n<p>\u4e00\u822c\u8bf4\u6765\uff0c\u6211\u4eec\u4f1a\u4ece host \u7a0b\u5e8f\u4e2d\u76f4\u63a5\u8c03\u7528\u5b83\uff0c\u4e5f\u5c31\u662f\u8c03\u7528 lua \u51fd\u6570\u5e76\u4e0d\u5728 lua \u4fdd\u62a4\u6a21\u5f0f\u4e2d\u3002luabind \u7684\u5b9e\u73b0\u8003\u8651\u4e86\u8fd9\u4e00\u70b9\uff0c\u6240\u4ee5\u00a0<code>call_function<\/code>\u00a0\u53ea\u4f1a\u7528\u00a0<code>lua_pcall<\/code>\u00a0\u800c\u4e0d\u4f1a\u4f7f\u7528\u53ef\u80fd\u4ea7\u751f\u5f02\u5e38\u7684\u00a0<code>lua_call<\/code>\u00a0\u3002<\/p>\n<p>\u95ee\u9898\u51fa\u5728\u83b7\u5f97\u51fd\u6570\u5bf9\u8c61\uff0c\u5904\u7406\u53c2\u6570\uff0c\u4ee5\u53ca\u5c06\u8fd4\u56de\u503c\u8f6c\u6362\u4e3a C++ \u5bf9\u8c61\u4e0a\u9762\u3002<\/p>\n<p>\u62bd\u4e1d\u5265\u8327\u7406\u89e3\u5176\u5b9e\u73b0\u975e\u5e38\u56f0\u96be\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u770b\u5176\u4e2d\u660e\u663e\u95ee\u9898\uff1a<\/p>\n<p><code>call_function<\/code>\u00a0\u7684\u4e3b\u4f53\u5b9e\u73b0\u5728\u00a0<a href=\"https:\/\/github.com\/luabind\/luabind\/blob\/master\/luabind\/detail\/call_function.hpp\">luabind\/detail\/call_function<\/a>\u00a0\u4e2d\u3002<\/p>\n<p>\u5982\u679c\u4f60\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32\u53bb\u5b9a\u4f4d\u5168\u5c40\u51fd\u6570\uff0c \u5728 445 \u884c\u53ef\u4ee5\u770b\u5230\uff1a<\/p>\n<pre>lua_pushstring(L, name);\r\nlua_gettable(L, LUA_GLOBALSINDEX);\r\n\r\nreturn proxy_type(L, 1, &amp;detail::pcall, args);\r\n<\/pre>\n<p>\u8fd9\u91cc\u7684\u00a0<code>lua_pushstring<\/code>\u00a0\u548c\u00a0<code>lua_gettable<\/code>\u00a0\u90fd\u662f\u6709\u53ef\u80fd\u629b\u51fa\u5f02\u5e38\u7684\uff0c\u4f46\u6ca1\u6709\u5728 pcall \u7684\u4fdd\u62a4\u4e2d\uff08pcall \u662f\u5728\u540e\u9762\u89e6\u53d1\u7684\uff09\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u5982\u679c\u4f60\u4e0d\u8003\u8651 oom \u9519\u8bef\uff0c\u4e5f\u4e0d\u8003\u8651\u5168\u5c40\u8868\u6709\u53ef\u80fd\u88ab\u4eba\u91cd\u8f7d\u4e86 index \u5143\u65b9\u6cd5\u800c\u53ef\u80fd\u51fa\u9519\u3002\u90a3\u4e48\u8fd9\u770b\u8d77\u6765\u8fd8\u662f\u4e2a\u5c0f\u95ee\u9898\u3002<\/p>\n<p>ps. \u5728 pcall \u524d\u5c06\u53c2\u6570\u538b\u5165 lua stack \u53ef\u80fd\u5f15\u53d1\u7684 OOM \u5c5e\u4e8e\u540c\u7c7b\u95ee\u9898\uff0c\u4e5f\u6682\u65f6\u4e0d\u8003\u8651\u3002<\/p>\n<p>\u518d\u6765\u770b\u4e00\u4e2a\u66f4\u4e3a\u4e25\u91cd\u7684\uff1a<\/p>\n<p><code>call_function<\/code>\u00a0\u7684\u8fd4\u56de\u503c\u662f\u7b49\u5230 pcall \u8fd4\u56de\u4e86\u4ee5\u540e\uff0c\u7531 template \u6307\u5b9a\u7684 Ret \u7c7b\u6765\u8f6c\u6362\u4e3a C++ \u5bf9\u8c61\u7684\u3002<\/p>\n<p>\u6211\u4eec\u5728\u00a0<a href=\"https:\/\/github.com\/luabind\/luabind\/blob\/master\/luabind\/detail\/call_function.hpp#L198-L215\">198 \u884c<\/a>\u00a0\u53ef\u4ee5\u770b\u5230\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u662f\u5728\u8c03\u7528\u00a0<code>m_fun<\/code>\u00a0\u4e5f\u5c31\u662f pcall \u4e4b\u540e\u7684\u3002\u5373\uff0c\u4ece lua \u503c\u5230 C++ \u5bf9\u8c61\u7684\u8f6c\u6362\u5e76\u6ca1\u6709\u88ab pcall \u4fdd\u62a4\u8d77\u6765\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u8bf4\u8fd9\u4e2a\u8fc7\u7a0b\u9690\u60a3\u5f88\u5927\uff1f\u56e0\u4e3a\u5f53\u4f60\u4ece lua string \u8f6c\u6362\u4e3a C++ string \u65f6\uff0c\u5176\u5b9e\u8c03\u7528\u7684\u662f\u00a0<code>lua_tostring<\/code>\u00a0(\u5177\u4f53\u89c1<a href=\"https:\/\/github.com\/luabind\/luabind\/blob\/87898f6012d553d7fe783ac1329ca47d45d262a7\/luabind\/detail\/policy.hpp#L748\">luabind\/detail\/policy.capp<\/a>\u00a0)<\/p>\n<p>\u8fd9\u4e2a api \u9664\u4e86 oom \u5f02\u5e38\u5916\uff0c\u8fd8\u6709\u5f88\u591a\u53ef\u80fd\u51fa\u9519\u3002\u56e0\u4e3a lua \u4e2d\u6240\u6709\u5bf9\u8c61\u90fd\u53ef\u4ee5\u9644\u52a0 tostring \u5143\u65b9\u6cd5\uff0c\u5728\u8f6c\u6362\u4e3a string \u65f6\uff0c\u4f1a\u6267\u884c\u4e00\u6bb5 lua \u4ee3\u7801\u3002\u8fd9\u5728 lua \u7a0b\u5e8f\u4e2d\u975e\u5e38\u5e38\u89c1\u3002<\/p>\n<p>\u800c\u6b63\u786e\u7684\u5c01\u88c5\u65b9\u6cd5\u5e94\u8be5\u662f\u4ece C++ \u4e2d\u8c03\u7528 lua \u51fd\u6570\u65f6\uff0c\u53c2\u6570\u7684\u4f20\u9012\u548c\u8fd4\u56de\u503c\u7684\u63a5\u6536\u548c\u5411 host \u8bed\u8a00\u8f6c\u6362\u90fd\u5e94\u8be5\u5305\u542b\u5728\u4e00\u4e2a\u00a0<code>lua_pcall<\/code>\u00a0\u4e0b\uff0c\u90a3\u4e2a\u771f\u6b63\u7684 lua \u51fd\u6570\u8c03\u7528\u4f7f\u7528\u00a0<code>lua_call<\/code>\u00a0\u5373\u53ef\u3002\u4f60\u4fbf\u53ef\u4ee5\u6b63\u786e\u6355\u83b7\u6574\u4e2a\u8fc7\u7a0b\u4e2d lua \u4ee3\u7801\u91cc\u7684\u9519\u8bef\u3002<\/p>\n<\/div>\n<\/div>\n<p class=\"entry-footer\"><span class=\"post-footers\">\u4e91\u98ce \u63d0\u4ea4\u4e8e May 14, 2015 04:07 PM<\/span>\u00a0<span class=\"separator\">|<\/span>\u00a0<a class=\"permalink\" href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html\">\u56fa\u5b9a\u94fe\u63a5<\/a><\/p>\n<\/div>\n<div id=\"comments\" class=\"comments\">\n<div class=\"comments-content\">\n<h3 class=\"comments-header\">COMMENTS<\/h3>\n<p><a id=\"c047102\"><\/a><\/p>\n<div id=\"comment-47102\" class=\"comment\">\n<div class=\"comment-content\">\n<p>@Cloud\uff0c\u6211\u662flua\u65b0\u624b\uff0c\u5bf9\u4e8elua\u7684\u5f02\u5e38\u5904\u7406\u6709\u4e9b\u56f0\u60d1\uff1a<\/p>\n<p>C++\u548clua\u4ea4\u4e92\u7684\u63a5\u53e3\uff0c\u6211\u73b0\u5728\u662f\u76f4\u63a5\u64cd\u4f5clua\u7684\u63a5\u53e3\uff0c\u6bd4\u5982\u5728C++\u8c03\u7528lua\u4e2d\u7684\u51fd\u6570\uff0c\u90fd\u662f\u8c03\u7528lua_pcall\uff0c\u5982\u679c\u6709\u9519\u8bef\uff0c\u5219\u4f7f\u7528luaL_error\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n<p>\u5bf9\u4e8e\u8c03\u7528lua_pcall\u7684\u9519\u8bef\uff0c\u662f\u5426\u53ea\u5e94\u8be5\u6253\u5370\u9519\u8bef\u4fe1\u606f\uff0c\u800c\u4e0d\u5e94\u8be5\u629b\u51fa\u5f02\u5e38\uff1f<\/p>\n<p>\u662f\u5426\u53ea\u5e94\u8be5\u5728\u51fd\u6570\u8c03\u7528\u7684\u53c2\u6570\u683c\u5f0f\u51fa\u73b0\u9519\u8bef\u65f6\uff0c\u6216\u8fd4\u56de\u6570\u636e\u683c\u5f0f\u9519\u8bef\u65f6\uff0c\u624d\u629b\u51fa\u5f02\u5e38\uff1f<\/p>\n<p>\u5982\u679cC++\u4e0elua\u4ea4\u4e92\u5168\u90e8\u4f7f\u7528\u4e2d\u95f4\u5c42\u7ed1\u5b9a\uff0c\u90a3\u4e48lua\u7684\u8fd4\u56de\u662f\u5426\u4e5f\u5e94\u5168\u90e8\u4f7f\u7528userdata\uff0c\u800c\u4e0d\u662f\u4f7f\u7528lua_toxxx\uff0c\u9632\u6b62\u5728lua_pcall\u540e\uff0c\u518d\u8c03\u7528lua_tostring\u4ecd\u7136\u4f1a\u629b\u51fa\u5f02\u5e38\u7684\u95ee\u9898\uff1f<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: affrog | (16)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-47102\">September 29, 2017 11:59 AM<\/a><\/p>\n<\/div>\n<p><a id=\"c047087\"><\/a><\/p>\n<div id=\"comment-47087\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u4f60\u597d\uff0c\u6211\u73b0\u5728\u5728\u5b66\u4e60c\u548clua\u7684\u4ea4\u4e92\uff0c\u6709\u4e2a\u95ee\u9898\u60f3\u95ee\u4f60\uff0cc\u5982\u4f55\u8c03\u7528lua\u8c03\u7528c\u5e93\u5f62\u6210\u7684\u51fd\u6570\uff0c\u6211\u73b0\u5728\u5361\u5230\u8fd9\u4e86\uff0cpcall\u51fd\u6570\u4e00\u76f4\u8fd4\u56de\u8fd0\u884c\u9519\u8bef\uff0c\u8c22\u8c22\u4e86\uff01<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: Anonymous | (15)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-47087\">September 19, 2017 04:01 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046567\"><\/a><\/p>\n<div id=\"comment-46567\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u4e00\u4e2a\u5c0f\u95ee\u9898\uff0clua_tostring\u5e76\u4e0d\u4f1a\u8c03\u7528tostring\u65b9\u6cd5\uff0c\u6240\u4ee5\u5728\u5ffd\u7565OOM\u9519\u8bef\u7684\u60c5\u51b5\u4e0b\u662f\u5b89\u5168\u7684\u3002<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by:\u00a0<a href=\"http:\/\/cheng.guru\/\" rel=\"nofollow\">zcbenz<\/a>\u00a0| (14)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-46567\">August 9, 2016 01:42 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046424\"><\/a><\/p>\n<div id=\"comment-46424\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u975e\u5e38\u597d\u7684\u4e00\u7bc7\u603b\u7ed3~\u611f\u8c22\u4e91\u5927\u65e0\u79c1\u5206\u4eab~<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: mrvon | (13)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-46424\">April 28, 2016 09:50 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c045803\"><\/a><\/p>\n<div id=\"comment-45803\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u6c42\u95ee\u4e00\u4e0b\uff1a<br \/>\n\u6211\u5728luajit2.0.4\u4e2d\uff0c\u60f3\u5f15\u5165lua5.1.4\u7684 json\u5305\uff0c\u5176\u4e2d\u542b\u6709 json.lua \u65f6\uff0c\u51fa\u73b0\u95ee\u9898\u3002\u6d4b\u8bd5\u53d1\u73b0\u6240\u6709\u7684 lua5.1.4\u4e0b lua\\*.*\u90fd\u65e0\u6cd5\u5f15\u5165\uff0c\u4e0d\u77e5\u9053\u60a8\u662f\u5426\u6709\u89e3\u51b3\u65b9\u6848\uff1f<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: Jonix | (12)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-45803\">June 10, 2015 10:17 AM<\/a><\/p>\n<\/div>\n<p><a id=\"c045771\"><\/a><\/p>\n<div id=\"comment-45771\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u5e76\u4e0d\u662f\u6bcf\u6b21\u8c03\u7528\u90fd\u52a0\u4e00\u5c42\uff0c\u662f\u5728 c \u548c lua \u8fb9\u754c\u4e0a\u52a0\u3002\u800c lua \u548c c \u7684\u5207\u6362\u672c\u8eab\u5c31\u5e94\u8be5\u63a7\u5236\u5728\u5f88\u5c11\u7684\u91cf\u7ea7\u3002<\/p>\n<p>\u8fd9\u4e9b\u5e76\u975e\u4f7f\u7528\u95ee\u9898\u3002\u8de8\u8bed\u8a00\u7684\u4e0d\u540c\u5f02\u5e38\u673a\u5236\u7684\u4ea4\u4e92\u672c\u8eab\u5c31\u662f\u5f88\u9ebb\u70e6\u7684\u3002\u5e94\u8be5\u907f\u514d\uff0c\u800c\u4e0d\u662f\u4efb\u5176\u5d29\u6e83\u3002<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: cloud | (11)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-45771\">May 19, 2015 11:15 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c045770\"><\/a><\/p>\n<div id=\"comment-45770\" class=\"comment\">\n<div class=\"comment-content\">\n<p>@Cloud \u53d7\u6559\u4e86<br \/>\n&#8212;&#8212;<br \/>\n\u53e6\u5916\u8fd8\u6709\u4e00\u4e9b\u7591\u8651<br \/>\n1\u3001\u6211\u89c9\u5f97\u8fd9\u4e9b\u8bbe\u8ba1\u91cc\u9762\u629b\u51fa\u7684\u5f02\u5e38\uff0c\u66f4\u591a\u7684\u662f\u4e0a\u5c42\u4f7f\u7528\u95ee\u9898\uff0c\u6362\u800c\u8a00\u4e4b\uff0c\u8fd9\u65f6\u5019\u7a0b\u5e8f\u76f4\u63a5\u5d29\u6389\u53ef\u80fd\u8fd8\u4f1a\u597d\u70b9<br \/>\n2\u3001\u53e6\u5916\u5c31\u662f\u4e3a\u4e86\u4e25\u683c\u505a\u5230\u8fd9\u79cd\u89c4\u8303\uff0c\u4f7f\u5f97\u51fd\u6570\u7684\u8c03\u7528\u6808\u53d8\u591a\uff0c\u90a3\u4e48\u81ea\u7136\u6548\u7387\u5c31\u4f1a\u6709\u6240\u4e0b\u964d\u3002\u4e0d\u662f\u8bf4\u4e0d\u597d\uff0c\u53ea\u662f\u8fd9\u79cd\u6027\u80fd\u4e0a\u7684\u4ee3\u4ef7\u662f\u5426\u771f\u7684\u503c\u5f97<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: \u571f\u532a | (10)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-45770\">May 19, 2015 10:24 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c045769\"><\/a><\/p>\n<div id=\"comment-45769\" class=\"comment\">\n<div class=\"comment-content\">\n<p>@\u571f\u532a<\/p>\n<p>\u8fd9\u7bc7 blog \u8bf4\u7684\u5c31\u662f: \u4f60\u65e0\u6cd5\u7528 `LUAI_TRY` \u6355\u83b7 lua api \u7684\u5f02\u5e38. \u552f\u4e00\u6b63\u786e\u7684\u65b9\u6cd5\u662f\u7528 `lua_pcall` \u5bf9\u4e8e\u66f4\u65e9\u7684\u7248\u672c\u6bd4\u5982 luajit, \u4f60\u5e94\u8be5\u4f7f\u7528 `lua_cpcall` .<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: Cloud | (9)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-45769\">May 19, 2015 12:20 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c045768\"><\/a><\/p>\n<div id=\"comment-45768\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u4f60\u8bf4\u7684\u8fd9\u91cc newvarsobject \u51fd\u6570\u662f\u95f4\u63a5\u88ab pcall \u8c03\u7528\u7684, \u5e76\u6ca1\u6709\u4efb\u4f55\u9014\u5f84\u53ef\u4ee5\u4ece C \u91cc\u76f4\u63a5\u8c03\u7528.<\/p>\n<p>\u8fd9\u91cc\u6709\u70b9\u95ee\u9898, \u6211\u6539\u4e00\u4e0b.<\/p>\n<p>\u6700\u574f\u60c5\u51b5\u662f `__gc` \u65b9\u6cd5\u6ca1\u6709\u88ab\u8bbe\u7f6e\u5230 metatable \u91cc. \u5bfc\u81f4\u65e0\u6cd5\u56de\u6536.<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: @\u571f\u532a | (8)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-45768\">May 19, 2015 12:07 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c045763\"><\/a><\/p>\n<div id=\"comment-45763\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u6211\u6839\u636e\u6587\u4e2d\u7684\u7406\u8bba\uff0c\u8fd9\u91cc\u7684\u5199\u6cd5\u662f\u4e0d\u7b26\u5408\u89c4\u8303\u7684<\/p>\n<p>\u5728196\u884c\u7684<br \/>\nstruct vars * v = lbind_new();<\/p>\n<p>\u8fd9\u91cc\u505a\u4e86\u7533\u8bf7\u5185\u5b58\u7684\u64cd\u4f5c<br \/>\n\u7136\u540e\u5728203\u884c<br \/>\nlua_setfield(L, -2, &#8220;__gc&#8221;);<\/p>\n<p>\u8fd9\u4e2a\u51fd\u6570\u662f\u6709\u53ef\u80fd\u62a5\u9519\u7684<br \/>\n\u6b64\u65f6\u4f1a\u51fa\u73b0\u5185\u5b58\u6cc4\u9732<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: \u571f\u532a | (7)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-45763\">May 18, 2015 02:29 AM<\/a><\/p>\n<\/div>\n<p><a id=\"c045762\"><\/a><\/p>\n<div id=\"comment-45762\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u770b\u8d77\u6765\uff0c\u5728lua\u4e2d\u8c03\u7528c\/c++\u51fd\u6570\u65f6\uff0c\u5982\u679c\u662f\u5b98\u65b9\u7684\u89e3\u6790\u5668\uff0c\u90a3\u4e48\u53ef\u4ee5\u4e0d\u7528\u8003\u8651\u5f02\u5e38\u7684\u95ee\u9898\uff08\u89e3\u6790\u5668\u5df2\u7ecf\u505a\u597d\u4e86\uff09\uff0c\u90a3\u4e48jit\u662f\u5426\u8981\u8003\u8651\u5462\uff1f<br \/>\n\u53e6\u5916\uff0cc\/c++ \u4e2d\u5982\u679c\u8c03\u7528\u4e86lua\u7684api,\u90a3\u4e48\u8981\u4f7f\u7528LUAI_TRY \u6765\u6355\u6349\u5f02\u5e38<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: \u571f\u532a | (6)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-45762\">May 18, 2015 01:51 AM<\/a><\/p>\n<\/div>\n<p><a id=\"c045761\"><\/a><\/p>\n<div id=\"comment-45761\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u4e3b\u903b\u8f91\u653e LUA \u91cc\u9762<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: \u7b11\u71ac\u6d46\u7cca | (5)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-45761\">May 16, 2015 07:01 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c045759\"><\/a><\/p>\n<div id=\"comment-45759\" class=\"comment\">\n<div class=\"comment-content\">\n<p>@actboy168<\/p>\n<p>\u6b63\u56e0\u4e3a\u505a\u4e25\u683c\u5f88\u9ebb\u70e6\uff0c\u6240\u4ee5\u4e0d\u4e3b\u5f20\u5728 host \u7a0b\u5e8f\u91cc\u968f\u610f\u4f7f\u7528 lua c api \u53bb\u64cd\u4f5c lua state \u4e2d\u7684\u6570\u636e\u3002<\/p>\n<p>\u4e5f\u5c31\u662f\u5e94\u8be5\u5728 host \u91cc\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u800c\u5b8c\u5907\u7684\u6a21\u5757\u628a lua \u5d4c\u5165\uff0c\u7136\u540e\u628a\u5176\u5b83\u7684\u529f\u80fd\u5b9e\u73b0\u6210 lua \u5e93\u3002<\/p>\n<p>\u5982\u679c host \u91cc\u6709\u591a\u4e2a\u70b9\u9700\u8981\u548c lua vm \u4ea4\u4e92\uff08\u4e5f\u5c31\u662f\u4e1a\u52a1\u4e3b\u6846\u67b6\u5728 host \u4e2d\u800c\u4e0d\u5728 lua vm \u4e2d\uff09\uff0c\u90a3\u4e48\u4ea4\u4e92\u63a5\u53e3\u5e94\u8be5\u8db3\u591f\u7b80\u5355\uff0c\u9700\u8981\u628a lua api \u90fd\u9690\u85cf\u8d77\u6765\u3002<\/p>\n<p>\u8fd9\u662f\u8fd9\u7bc7 blog \u60f3\u8868\u8fbe\u7684\u4e2d\u5fc3\u610f\u601d\u3002<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: Cloud | (4)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-45759\">May 14, 2015 10:17 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c045758\"><\/a><\/p>\n<div id=\"comment-45758\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u9053\u7406\u90fd\u660e\u767d\uff0c\u5c31\u662f\u592a\u9ebb\u70e6\uff0c\u4e00\u76f4\u6ca1\u505a\u5f97\u8fd9\u4e48\u4e25\u683c<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: actboy168 | (3)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-45758\">May 14, 2015 09:12 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c045757\"><\/a><\/p>\n<div id=\"comment-45757\" class=\"comment\">\n<div class=\"comment-content\">\n<p>[-0, +1, e] \u5927\u795e\uff0c\u8fd9\u4e2a\u662f\u5565\u610f\u601d<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: mason | (2)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2015\/05\/lua_c_api.html#comment-45757\">May 14, 2015 07:57 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c045756\"><\/a><\/p>\n<div id=\"comment-45756\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u770b\u5230\u8fd9\u4e9b\uff0c\u6211\u60f3\u8d77\u6211\u4e4b\u524d\u5c01\u88c5lua\u865a\u62df\u673a\u7ed9node.js\u6765\u8c03\u7528\uff0c\u91cc\u9762\u6211\u505a\u4e86js\u865a\u62df\u673a\u548clua\u865a\u62df\u673a\u76f8\u4e92\u4f20\u9012\u6570\u636e\uff0c\u4ed4\u7ec6\u60f3\u60f3\u91cc\u9762\u786e\u5b9e\u7528\u5230\u4e86\u4f1a\u629b\u51fa\u5f02\u5e38\u7684\u51fd\u6570\uff0c\u73b0\u5728\u5f00\u59cb\u540e\u6015\u4e86\u3002\u3002\u3002<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Lua C API \u7684\u6b63\u786e\u7528\u6cd5 Lua <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[118],"class_list":["post-1298","post","type-post","status-publish","format-standard","hentry","tag-02-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=1298"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1298\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=1298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=1298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=1298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}