{"id":1045,"date":"2018-03-29T17:18:14","date_gmt":"2018-03-29T09:18:14","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=1045"},"modified":"2018-03-29T17:18:14","modified_gmt":"2018-03-29T09:18:14","slug":"%e5%a6%82%e4%bd%95%e8%ae%a9-lua-%e5%81%9a%e5%b0%bd%e9%87%8f%e6%ad%a3%e7%a1%ae%e7%9a%84%e7%83%ad%e6%9b%b4%e6%96%b0","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/1045","title":{"rendered":"\u5982\u4f55\u8ba9 lua \u505a\u5c3d\u91cf\u6b63\u786e\u7684\u70ed\u66f4\u65b0"},"content":{"rendered":"<div id=\"entry-1027\" class=\"entry\">\n<h3 class=\"entry-header\">\u5982\u4f55\u8ba9 lua \u505a\u5c3d\u91cf\u6b63\u786e\u7684\u70ed\u66f4\u65b0<\/h3>\n<div class=\"entry-content\">\n<div class=\"entry-body\">\n<p>\u5f88\u591a\u9879\u76ee\u91c7\u7528 lua \u7684\u4e00\u5927\u539f\u56e0\u662f lua \u53ef\u4ee5\u65b9\u4fbf\u7684\u505a\u70ed\u66f4\u65b0\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u5728\u4e0d\u4e2d\u65ad\u8fdb\u7a0b\u8fd0\u884c\u7684\u60c5\u51b5\u4e0b\uff0c\u628a\u4fee\u6539\u8fc7\u7684\u4ee3\u7801\u585e\u5230\u8fdb\u7a0b\u4e2d\uff0c\u8ba9\u968f\u540e\u7684\u8fc7\u7a0b\u8fd0\u884c\u65b0\u7248\u672c\u7684\u4ee3\u7801\u3002\u8fd9\u5f97\u76ca\u4e8e lua \u7684 function \u662f first class \u5bf9\u8c61\uff0c\u6362\u6389\u4ee3\u7801\u4e0d\u8fc7\u662f\u5728\u8ba9\u76f8\u5e94\u7684\u53d8\u91cf\u6307\u5411\u65b0\u7684 function \u5bf9\u8c61\u800c\u5df2\u3002<\/p>\n<p>\u4f46\u4e5f\u6b63\u56e0\u4e3a lua \u7684\u8fd9\u79cd\u7075\u6d3b\u6027\uff0c\u60f3\u628a\u70ed\u66f4\u65b0\u4ee3\u7801\u8fd9\u4ef6\u4e8b\u505a\u7684\u901a\u7528\uff0c\u4e14 100% \u505a\u5bf9\uff0c\u53c8\u51e0\u4e4e\u662f\u4e0d\u592a\u53ef\u80fd\u7684\u3002<\/p>\n<p>\u9996\u5148\uff0c\u4f60\u5f88\u96be\u51c6\u786e\u7684\u5b9a\u4e49\u51fa\uff0c\u4ec0\u4e48\u53eb\u505a\u66f4\u65b0\uff0c\u54ea\u4e9b\u6570\u636e\u9700\u8981\u4fdd\u7559\uff0c\u54ea\u4e9b\u9700\u8981\u66ff\u6362\u6210\u65b0\u7248\u672c\u3002\u5149\u4ece\u6e90\u4ee3\u7801\u548c\u8fd0\u884c\u65f6\u7684\u5143\u4fe1\u606f\u4e0a\u53bb\u5206\u6790\u662f\u8fdc\u8fdc\u4e0d\u591f\u7684\u3002<\/p>\n<p>lua \u53ea\u6709\u4e00\u79cd\u901a\u7528\u6570\u636e\u7ed3\u6784 table \uff0c\u8fd9\u65b9\u4fbf\u4e86\u6211\u4eec\u505a\u6570\u636e\u66f4\u65b0\uff1b\u4f46\u540c\u65f6\u4e5f\u5236\u9020\u4e86\u4e00\u4e9b\u6a21\u7cca\u6027\u96be\u9898\u3002\u6bd4\u5982\uff0c\u5982\u679c\u5728\u4ee3\u7801\u4e2d\u6709\u4e00\u4e9b\u5e38\u91cf\u914d\u7f6e\u6570\u636e\u8868\uff0c\u5199\u6b7b\u5728\u6e90\u4ee3\u7801\u4e2d\uff0c\u901a\u5e38\u4f60\u662f\u5e0c\u671b\u8ddf\u7740\u65b0\u7248\u672c\u4e00\u8d77\u66f4\u65b0\u7684\uff1b\u800c\u6709\u4e00\u4e9b\u8868\uff0c\u8bb0\u5f55\u7740\u8fd0\u884c\u65f6\u7684\u72b6\u6001\uff0c\u4f60\u53c8\u4e0d\u5e0c\u671b\u5728\u4ee3\u7801\u66f4\u65b0\u540e\u72b6\u6001\u6e05\u7a7a\u3002<\/p>\n<p>\u6240\u4ee5\u4e00\u822c\u505a\u70ed\u66f4\u65b0\u65b9\u6848\u7684\u65f6\u5019\uff0c\u90fd\u4f1a\u4eba\u4e3a\u52a0\u4e00\u4e9b\u7ea6\u675f\uff0c\u5728\u9075\u5faa\u7ea6\u675f\u6761\u4ef6\u7684\u524d\u63d0\u4e0a\uff0c\u5c3d\u91cf\u8ba9\u66f4\u65b0\u7b26\u5408\u9884\u671f\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/cloudwu\/skynet\/wiki\/Snax\">\u6bd4\u5982\u5728 skynet \u4e2d\u5c31\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u70ed\u66f4\u65b0\u65b9\u6cd5<\/a>\u00a0\u3002<\/p>\n<\/div>\n<div id=\"more\" class=\"entry-more\">\n<p>\u6700\u8fd1\u5728\u7ed9\u516c\u53f8\u7684\u9879\u76ee\u505a\u4e00\u4e9b\u6280\u672f\u6307\u5bfc\uff0c\u540c\u65f6\u4e5f\u505a\u4e00\u4e9b\u5de5\u5177\u6765\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u5bf9\u4e8e\u5f00\u53d1\u671f\uff08\u800c\u4e0d\u662f\u751f\u4ea7\u73af\u5883\uff09\uff0c\u6216\u8bb8\u63d0\u4f9b\u4e00\u4e2a\u66f4\u7075\u6d3b\u7684\u70ed\u66f4\u65b0\u65b9\u6848\u66f4\u65b9\u4fbf\u4e00\u4e9b\u3002\u6211\u4eec\u4e0d\u592a\u9700\u8981\u7ed3\u679c 100% \u6b63\u786e\uff0c\u4f46\u662f\u9700\u8981\u51cf\u5c11\u4e00\u4e9b\u7ea6\u675f\u3002<\/p>\n<p>\u5728\u5f00\u53d1\u671f\uff0c\u6700\u597d\u5c31\u662f\u6539\u4e24\u884c\u4ee3\u7801\uff0c\u80fd\u7acb\u523b\u8ba9\u8fdb\u7a0b\u5237\u65b0\u6210\u65b0\u7248\u672c\u7684\u4ee3\u7801\uff0c\u5e76\u4e0d\u4e2d\u65ad\u8fd0\u884c\u3002\u5982\u679c\u66f4\u65b0\u7ed3\u679c\u548c\u9884\u671f\u4e0d\u7b26\uff0c\u6700\u574f\u7684\u540e\u679c\u4e5f\u4e0d\u8fc7\u662f\u5173\u6389\u7a0b\u5e8f\u91cd\u65b0\u6765\u800c\u5df2\u3002\u4f46\u662f\u5982\u679c\u4ec5\u4ec5\u662f\u6539\u4e24\u884c\u4ee3\u7801\uff0c\u6216\u52a0\u51e0\u884c log \uff0c\u5219\u57fa\u672c\u4e0d\u4f1a\u51fa\u9519\uff0c\u4f46\u5f00\u53d1\u6548\u7387\u5374\u53ef\u4ee5\u6781\u5927\u7684\u63d0\u9ad8\u3002<\/p>\n<hr \/>\n<p>\u4e0b\u9762\u6765\u8ba8\u8bba\u4e00\u4e0b\uff0c\u5728\u7ea6\u675f\u6761\u4ef6\u8db3\u591f\u5c11\u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u4f55\u8bbe\u8ba1\u4e00\u4e2a\u5c3d\u91cf\u5b8c\u5907\u7684\u70ed\u66f4\u65b0\u65b9\u6848\u3002<\/p>\n<p>\u70ed\u66f4\u65b0\u7684\u5173\u952e\u662f\uff1a\u627e\u5230\u66f4\u65b0\u7684\u4ee3\u7801\u6a21\u5757\u548c\u5728\u5185\u5b58\u4e2d\u8fd0\u884c\u7684\u5bf9\u5e94\u6a21\u5757\uff0c\u5230\u5e95\u6709\u4ec0\u4e48\u5dee\u5f02\uff0c\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u8fd9\u4e9b\u5dee\u5f02\u3002<\/p>\n<p>\u5982\u679c\u6211\u4eec\u4ee5\u6a21\u5757\u4e3a\u5355\u4f4d\u6765\u66f4\u65b0\uff0c\u7b2c\u4e00\u6b65\u5c31\u662f\u8981\u628a\u8981\u5904\u7406\u7684\u6570\u636e\u7ea6\u675f\u5728\u4e00\u4e2a\u8db3\u591f\u5c0f\u7684\u8303\u7574\uff0c\u800c\u4e0d\u80fd\u6269\u5927\u5230\u6574\u4e2a\u865a\u62df\u673a\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u5148\u5b9e\u73b0\u4e86\u4e00\u4e2a\u6c99\u76d2\uff0c\u8ba9 require \u65b0\u6a21\u5757\u7684\u8fc7\u7a0b\u5728\u6c99\u76d2\u4e2d\u8fd0\u884c\u3002\u6211\u4eec\u53ea\u7ed9\u6c99\u76d2\u6ce8\u5165\u6709\u9650\u7684\u51e0\u4e2a\u4e0d\u4f1a\u4ea7\u751f\u526f\u4f5c\u7528\u7684\u51fd\u6570\uff0c\u6bd4\u5982 print \uff0crequire\uff0cpairs \u7b49\uff1b\u53ea\u5141\u8bb8\u5728\u6a21\u5757\u521d\u59cb\u5316\u6d41\u7a0b\u4e2d\u8c03\u7528\u8fd9\u4e9b\u65e0\u526f\u4f5c\u7528\u7684\u51fd\u6570\u3002\u90a3\u4e48\uff0c\u5f53\u6a21\u5757\u521d\u59cb\u5316\u597d\u4e4b\u540e\uff0c\u6574\u4e2a\u6a21\u5757\u5185\u90e8\u7684\u6570\u636e\uff08\u51fd\u6570\u4e5f\u662f\u6570\u636e\uff09\uff0c\u90fd\u4e0d\u4f1a\u6ea2\u51fa\u6c99\u76d2\uff08\u4e0d\u4f1a\u6709\u5f15\u7528\u6307\u5411\u6c99\u76d2\u5916\uff09\u3002<\/p>\n<p>\u7531\u4e8e lua \u7684\u6570\u636e\u7ed3\u6784\u5f88\u7b80\u5355\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u8ba4\u4e3a\u6c99\u76d2\u4e2d\u653e\u7740\u4e00\u5f20\u53ea\u6709 function \u548c table \u4e24\u79cd\u590d\u6742\u6570\u636e\u7c7b\u578b\u6784\u6210\u7684\u56fe\u3002\u8fd9\u662f\u56e0\u4e3a coroutine.* setmetatable io.* \u7b49\u8fd9\u4e9b\u53ef\u80fd\u4ea7\u751f\u5176\u5b83\u7c7b\u578b\u6570\u636e\u7684\u51fd\u6570\u90fd\u4e0d\u80fd\u5728\u521d\u59cb\u5316\u9636\u6bb5\u8c03\u7528\uff0c\u8fd9\u662f\u4e00\u4e2a\u5408\u7406\u7684\u9650\u5236\u6761\u4ef6\u3002<\/p>\n<p>\u8fd9\u4e2a\u9650\u5236\u6761\u4ef6\u540c\u6837\u4e5f\u80fd\u89c4\u8303\u6a21\u5757\u7684\u5f00\u53d1\u65b9\u6cd5\u3002\u6bd4\u5982\u82e5\u6709\u590d\u6742\u7684\u521d\u59cb\u5316\u6d41\u7a0b\u5fc5\u987b\u63d0\u4f9b\u4e00\u4e2a\u6a21\u5757\u7684\u521d\u59cb\u5316\u51fd\u6570\uff0c\u7531\u5916\u90e8\u9a71\u52a8\uff0c\u800c\u4e0d\u80fd\u76f4\u63a5\u5199\u5728\u6a21\u5757\u7684\u52a0\u8f7d\u6d41\u7a0b\u4e2d\uff0c\u8fd9\u4e5f\u56de\u907f\u4e86\u66f4\u65b0\u6a21\u5757\u4ee3\u7801\u65f6\u7684\u91cd\u590d\u521d\u59cb\u5316\u8fc7\u7a0b\u3002<\/p>\n<p>\u5728\u5236\u4f5c\u6c99\u76d2\u65f6\uff0c\u53ef\u4ee5\u5efa\u7acb\u4e00\u4e2a\u8bbf\u95ee\u5168\u5c40\u53d8\u91cf\u548c\u5176\u5b83\u6a21\u5757\u5185\u5bb9\u7684 dummy \u65b9\u6cd5\u3002\u4e00\u4e9b lua \u5e38\u7528\u5199\u6cd5\u5c31\u53ef\u4ee5\u652f\u6301\uff0c\u6bd4\u5982\uff1a<\/p>\n<pre>local debug = require \"debug\"\r\nlocal tinsert = table.insert\r\nlocal getinfo = debug.getinfo\r\n<\/pre>\n<p>\u8fd9\u7c7b\u5e38\u89c1\u7684\u5199\u6cd5\u662f\u53ef\u4ee5\u652f\u6301\u7684\uff0c\u53ea\u4e0d\u8fc7\u8fd9\u4e9b local \u53d8\u91cf\u5728\u6c99\u76d2\u4e2d\u8fd0\u884c\u65f6\uff0c\u6307\u5411\u7684\u662f\u4e00\u4e2a dummy \u5bf9\u8c61\uff1b\u5f53\u66f4\u65b0\u6a21\u5757\u6210\u529f\u540e\uff0c\u53ef\u4ee5\u540e\u7eed\u66ff\u6362\u6210\u771f\u6b63\u7684\u53d8\u91cf\u3002\u4f46\u662f\uff0c\u5728\u6a21\u5757\u521d\u59cb\u5316\u8fc7\u7a0b\u8c03\u7528\u5b83\u4eec\u4f1a\u5931\u8d25\u3002<\/p>\n<p>\u7b2c\u4e8c\u6b65\uff0c\u6211\u4eec\u53ef\u4ee5\u5206\u6790\u6c99\u76d2\u4e2d\u7684\u6570\u636e\u56fe\u3002\u4e3a\u4e86\u7b80\u5316\u5b9e\u73b0\uff0c\u6211\u4eec\u8981\u6c42\u6570\u636e\u56fe\u7684\u521d\u59cb\u72b6\u6001 key \u90fd\u5fc5\u987b\u662f string \u6216 number \u7b49\u503c\u7c7b\u578b\u3002\u8fd9\u5e94\u8be5\u4e5f\u7b97\u4e00\u4e2a\u5408\u7406\u7684\u8981\u6c42\u3002\u867d\u7136 key \u662f table \u6216 function \u4e5f\u80fd\u5b9e\u73b0\uff0c\u4f46\u4ee3\u7801\u4f1a\u590d\u6742\u5f88\u591a\uff0c\u4e0d\u503c\u5f97\u653e\u5bbd\u8fd9\u4e2a\u9650\u5236\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6c99\u76d2\u4e2d\u6bcf\u4e2a table \u548c function \u90fd\u53ef\u4ee5\u8868\u8fbe\u4e3a\u4e00\u4e2a\u7b80\u5355\u503c\u7c7b\u578b\u5e8f\u5217\u7d22\u5f15\u5230\u7684\u4e1c\u897f\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u6bcf\u6761\u8def\u5f84\u53bb\u5bf9\u6bd4\u5185\u5b58\u4e2d\u540c\u6837\u8def\u5f84\u4e0a\u7684\u5bf9\u8c61\uff0c\u627e\u5230\u5b83\u7684\u8001\u7248\u672c\u3002\u5bf9\u4e8e function \u53d8\u6210 table \u6216 table \u53d8\u6210 function \u8fd9\u79cd\u60c5\u51b5\uff0c\u901a\u901a\u8ba4\u4e3a\u662f\u6709\u4e8c\u4e49\u6027\u7684\uff0c\u53ef\u4ee5\u7b80\u5355\u62d2\u7edd\u70ed\u66f4\u65b0\u3002\u6211\u4eec\u7684\u539f\u5219\u662f\uff0c\u5728\u7ea6\u675f\u6761\u4ef6\u4e0b\u5c3d\u91cf\u4e0d\u51fa\u9519\uff0c\u5982\u679c\u505a\u5c31\u505a\u5bf9\u3002<\/p>\n<p>\u8fd9\u6837\uff0c\u95ee\u9898\u5c31\u53d8\u7b80\u5355\u4e86\uff1a\u627e\u5230\u4e86\u5bf9\u8c61\u4e4b\u95f4\u7684\u65b0\u8001\u7248\u672c\u5bf9\u540e\uff0c\u5c31\u662f\u600e\u4e48\u66ff\u6362\u7684\u95ee\u9898\u3002\u5982\u679c\u65b0\u7248\u672c\u4e2d\u6709\u5bf9\u8c61\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48\u4e0d\u7528\u5220\u9664\u8001\u7248\u672c\uff0c\u56e0\u4e3a\u5982\u679c\u8001\u7248\u672c\u65e0\u4eba\u4f7f\u7528\uff0c\u90a3\u4e48\u5c31\u968f\u5b83\u53bb\u597d\u4e86\uff1b\u5982\u679c\u65b0\u7248\u672c\u5bf9\u8001\u7248\u672c\u6709\u65b0\u589e\uff0c\u76f4\u63a5\u52a0\u5165\u65b0\u5bf9\u8c61\u3002<\/p>\n<p>\u5bf9\u4e8e\u540c\u7c7b\u5bf9\u8c61\u66ff\u6362\uff1a\u51fd\u6570\u5f53\u7136\u662f\u7528\u65b0\u7248\u672c\u66ff\u6362\u8001\u7248\u672c\uff0c\u4f46\u662f\u8981\u5c0f\u5fc3\u7684\u5904\u7406 upvalue \uff0c\u8fd9\u4e2a\u4e0b\u9762\u5c55\u5f00\u8bf4\uff1b\u5bf9\u4e8e table \uff0c\u6211\u7684\u5efa\u8bae\u662f\u76f4\u63a5\u628a\u65b0\u7248\u672c\u7684 k\/v \u63d2\u5165\u8001\u7248\u672c\u7684 table \uff0c\u53d6\u5e76\u96c6\u3002\u8fd9\u79cd\u5408\u5e76 table \u7684\u89c4\u5219\u6700\u4e3a\u7b80\u5355\u3002<\/p>\n<p>upvalue \u5982\u4f55\u5408\u5e76\u5462\uff1f<\/p>\n<p>upvalue \u5176\u5b9e\u662f lua \u4e2d\u7684\u4e00\u4e2a\u9690\u5f0f\u7c7b\u578b\uff0c\u5927\u81f4\u76f8\u5f53\u4e8e C++ \u7684\u5f15\u7528\u7c7b\u3002\u6bd4\u5982\uff1a<\/p>\n<pre>local a = {}\r\n\r\nfunction foo()\r\n  return a\r\nend\r\n<\/pre>\n<p>a \u662f foo \u7684\u4e00\u4e2a upvalue \uff0c\u5728 lua \u4e2d a \u7684\u7c7b\u578b\u662f table \uff0c\u4f46 upvalue \u7684\u5b9e\u9645\u7c7b\u578b\u5374\u4e0d\u662f\u3002\u56e0\u4e3a\u4f60\u53ef\u4ee5\u5728\u522b\u5904\u4fee\u6539 a \uff0cfoo \u8fd4\u56de\u503c\u4e5f\u4f1a\u8ddf\u7740\u6539\u53d8\u3002<\/p>\n<p>lua \u63d0\u4f9b\u4e86\u4e24\u4e2a api \uff1adebug.upvalueid \u548c debug.upvaluejoin \u6765\u64cd\u4f5c upvalue \u3002<\/p>\n<p>\u6211\u5efa\u8bae\u7684\u89c4\u5219\u662f\uff0c\u5f53\u6211\u4eec\u9700\u8981\u628a f1 \u66ff\u6362\u6210 f2 \u65f6\uff0c\u5e94\u8be5\u53d6\u51fa f2 \u7684\u6240\u6709 upvalue \uff0c\u6309\u540d\u5b57 join \u7ed9 f1 \u3002\u4e0d\u8fc7\u8fd9\u91cc\u5b58\u5728\u7684\u95ee\u9898\u662f\uff0c f1 \u5982\u679c\u65b0\u589e\u4e86 upvalue \u8be5\u600e\u4e48\u529e\uff1f\u3002<\/p>\n<p>\u6211\u4eec\u4e0d\u80fd\u7b80\u5355\u7684\u4fdd\u7559 f1 \u65b0\u589e\u7684 upvalue \uff0c\u6bd4\u5982\uff1a<\/p>\n<pre>--\u8001\u7248\u672c\r\nlocal a,b\r\n\r\nfunction foo()\r\n  return a\r\nend\r\n\r\nfunction foo2()\r\n  return b\r\nend\r\n\r\n-- \u65b0\u7248\u672c\r\nlocal a,b\r\n\r\nfunction foo()\r\n  return a,b\r\nend\r\n\r\nfunction foo2()\r\n  return b\r\nend\r\n<\/pre>\n<p>\u8fd9\u91cc\u8001\u7248 foo \u53ea\u6709\u4e00\u4e2a upvalue a \uff0c\u4f46\u65b0\u7248 foo \u6709\u4e24\u4e2a a \u548c b \u3002\u6211\u4eec\u5728\u5904\u7406 foo \u66f4\u65b0\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u628a\u8001\u7248\u7684 a \u5173\u8054\u7ed9\u65b0\u7248\u7684 foo \uff1b\u4f46\u5728\u8001\u7248\u7684 foo \u4e2d\uff0c\u5374\u65e0\u6cd5\u627e\u5230 b \u3002<\/p>\n<p>\u5982\u679c\u6211\u4eec\u4e0d\u7406\u4f1a\u65b0\u589e\u7684 b \u8ba9\u5176\u4fdd\u7559\u5728 foo \u4e0a\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u5c31\u4f1a\u51fa\u73b0 foo2 \u7684 b \u88ab\u5173\u8054\u8d70\uff1b\u7ed3\u679c\u5728\u65b0\u7248\u672c\u4e2d\uff0c foo \u548c foo2 \u539f\u672c\u5171\u4eab\u7684 b \u53d8\u6210\u4e86\u4e24\u4e2a\u3002<\/p>\n<p>\u6240\u4ee5\u6b63\u786e\u7684\u505a\u6cd5\u662f\uff0c\u628a\u4e00\u4e2a\u6a21\u5757\u4e2d\u6240\u6709\u7684\u51fd\u6570\u5bf9\u8c61\u4e00\u8d77\u5904\u7406\uff0c\u6240\u6709\u5904\u7406\u8fc7\u7684 upvalue \u4ee5upvalueid \u4e3a\u7d22\u5f15\u8bb0\u5f55\u5728\u4e00\u8d77\uff0c\u8fd9\u6837\u5728\u63a8\u5bfc upvalue \u7684\u5f52\u5c5e\u65f6\uff0c\u53ef\u4ee5\u4fdd\u6301\u540c\u4e00\u7248\u672c\u4e2d\u7684\u5173\u8054\u6027\u3002<\/p>\n<p>\u5982\u679c\u63a8\u5bfc\u4ea7\u751f\u4e86\u6b67\u4e49\uff0c\u4f8b\u5982\u65b0\u7248\u672c\u4e2d\u4e24\u4e2a\u51fd\u6570\u5171\u4eab\u4e00\u4e2a upvalue \uff0c\u800c\u8001\u7248\u4e2d\u662f\u5206\u79bb\u7684\uff0c\u90a3\u4e48\u90fd\u8ba4\u4e3a\u4ee3\u7801\u6709\u4e8c\u4e49\u6027\uff0c\u62d2\u7edd\u66f4\u65b0\u3002<\/p>\n<p>\u518d\u8003\u8651\u8fd9\u79cd\u60c5\u51b5\uff1a<\/p>\n<pre>local mod = {}\r\n\r\nlocal pool = {}\r\n\r\nfunction mod.foo()\r\n    return function()\r\n        return pool\r\n    end\r\nend\r\n<\/pre>\n<p>\u8fd9\u91cc\uff0cmod.foo() \u8fd4\u56de\u4e00\u4e2a\u51fd\u6570\uff0c\u5f15\u7528\u4e86 pool \u3002\u8fd9\u70b9\uff0c\u5728\u521d\u59cb\u5316 mod \u7684\u65f6\u5019\uff0c\u8be5\u51fd\u6570\u662f\u4e0d\u5b58\u5728\u7684\uff0c\u6240\u4ee5\u65e0\u6cd5\u88ab\u5206\u6790\u5230\u3002\u6240\u4ee5\u5728\u5408\u5e76\u5bf9\u8c61\uff0c\u5904\u7406 upvalue \u7684\u65f6\u5019\uff0c\u5fc5\u987b\u5c06\u65b0\u7248 upvalue \u7684\u503c\u5408\u5e76\u5230\u8001\u7248 upvalue \u4e2d\uff0c\u518d\u5c06\u65b0\u7248 function \u7684 upvalue join \u5230\u8001\u7248\u7684 upvalue \uff1b\u4e0d\u53ef\u4ee5\u53cd\u8fc7\u6765\u505a\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u8fd9\u91cc\u8fd4\u56de\u7684\u90a3\u4e2a\u533f\u540d\u51fd\u6570 function() return pool end \uff0c\u5982\u679c\u4e00\u65e6\u88ab\u6301\u6709\uff0c\u65e7\u7248\u672c\u662f\u65e0\u6cd5\u88ab\u66f4\u65b0\u6210\u65b0\u7248\u672c\u7684\u3002<\/p>\n<hr \/>\n<p>\u7531\u4e8e\u6211\u4eec\u53ef\u4ee5\u5148\u5728\u6c99\u76d2\u4e2d\u5c3d\u91cf\u628a\u6709\u6548\u6027\u68c0\u67e5\u5168\u90e8\u505a\u5b8c\uff0c\u6240\u4ee5\u4e0d\u4f1a\u51fa\u73b0\u66f4\u65b0\u4e86\u4e00\u534a\u7684\u72b6\u6001\u51fa\u9519\uff0c\u8ba9\u5185\u5b58\u4e2d\u7684\u72b6\u6001\u5904\u4e8e\u4e2d\u95f4\u72b6\u6001\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u53ea\u9700\u8981\u904d\u5386\u6574\u4e2a VM \uff0c\u628a\u6240\u6709\u5f15\u7528\u8001\u7248\u672c\u51fd\u6570\u7684\u5730\u65b9\uff0c\u4fee\u6539\u4e3a\u65b0\u7248\u672c\u5bf9\u5e94\u51fd\u6570\u3002\u6574\u4e2a\u5de5\u4f5c\u5c31\u5b8c\u6210\u4e86\u3002<\/p>\n<hr \/>\n<p>\u8bf4\u8d77\u6765\u5bb9\u6613\uff0c\u505a\u8d77\u6765\u8fd8\u662f\u5f88\u9ebb\u70e6\u7684\u3002\u6211\u82b1\u4e86\u4e24\u5929\u7684\u65f6\u95f4\u624d\u628a\u5b9e\u73b0\u57fa\u672c\u5b8c\u6210\u3002<a href=\"https:\/\/github.com\/cloudwu\/luareload\/\">\u653e\u5728 github \u4e0a<\/a>\u3002<\/p>\n<p>\u76ee\u524d\u8fd8\u6ca1\u6709\u4ed4\u7ec6\u6d4b\u8bd5\uff0c\u6709\u65f6\u95f4\u6211\u4f1a\u518d review \u4e00\u904d\u3002\u6b63\u5982\u6587\u7ae0\u524d\u9762\u6240\u8bf4\uff0c\u5728\u6211\u4eec\u7684\u5e94\u7528\u573a\u5408\uff08\u7528\u4e8e\u5f00\u53d1\u671f\u8c03\u8bd5\uff09\uff0c\u6b63\u786e\u6027\u6682\u65f6\u6ca1\u6709\u592a\u9ad8\u7684\u8981\u6c42\uff0c\u6240\u4ee5\u53ef\u4ee5\u5148\u5c06\u5c31\u7740\u7528\u7528\u5427\u3002 \ud83d\ude42 \u5982\u679c\u4f60\u60f3\u5728\u4f60\u7684\u9879\u76ee\u5229\u7528\u5b83\u505a\u66f4\u591a\u7684\u4e8b\u60c5\uff0c\u6b22\u8fce\u4f7f\u7528\uff0c\u4f46\u8bf7\u7559\u610f\u53ef\u80fd\u51fa\u73b0\u7684 bug \u3002\u6b22\u8fce\u4fee\u6b63 bug \u540e\u63d0\u4ea4\u4e00\u4e2a pull request \u3002<\/p>\n<hr \/>\n<p>11 \u6708 25 \u65e5\u8865\uff1a<\/p>\n<p>\u5173\u4e8e\u524d\u9762\u63d0\u5230\u7684\u9650\u5236\uff0c\u5982\u679c\u65e7\u6709\u6a21\u5757\u4e2d\u6709\u51fd\u6570\u8fd4\u56de\u4e86\u4e00\u4e2a\u51fd\u6570\uff0c\u8fd9\u4e2a\u8fd4\u56de\u7684\u51fd\u6570\u867d\u7136\u5c5e\u4e8e\u8fd9\u4e2a\u6a21\u5757\uff0c\u4f46\u662f\u5374\u662f\u65e0\u6cd5\u66f4\u65b0\u7684\u3002\u53ea\u80fd\u505a\u5230\uff0c\u65b0\u7684\u7248\u672c\u518d\u8c03\u7528\u51fd\u6570\u751f\u6210\u5b83\u65f6\uff0c\u65b0\u7684\u7248\u672c\u88ab\u66f4\u65b0\uff0c\u5df2\u6709\u7684\u7684\u51fd\u6570\u5219\u53ea\u80fd\u4fdd\u6301\u539f\u6837\u3002<\/p>\n<p>\u8fd9\u4e2a\u9650\u5236\u7684\u6839\u6e90\u5728\u4e8e\uff0c\u91cd\u65b0\u52a0\u8f7d\u7684\u6a21\u5757\u65b0\u7248\u672c\uff0c\u5728\u52a0\u8f7d\u5b8c\u6210\u540e\uff0c\u5bf9\u5e94\u7684\u51fd\u6570\u5e76\u4e0d\u5b58\u5728\u3002\u56e0\u4e3a\u5bf9\u4e8e lua \uff0cfunction \u662f first class \u7684\u3002\u8fc7\u53bb\u7684\u8fd0\u884c\u4e2d\uff0c\u53ef\u80fd\u5df2\u6784\u5efa\u4e86\u5f88\u591a\u8fd9\u6837\u7684\u51fd\u6570\u5bf9\u8c61\uff0c\u6bcf\u4e2a\u90fd\u662f\u4e0d\u540c\u7684\uff08\u5982\u679c upvalue \u4e0d\u540c\uff09\uff0c\u800c\u5982\u679c\u66f4\u6362\u6210\u65b0\u7248\u672c\u7684\u51fd\u6570\uff0c\u5fc5\u987b\u901a\u8fc7\u8c03\u7528\u5df2\u6709\u7684\u51fd\u6570\u624d\u80fd\u6784\u5efa\u51fa\u6765\uff0c\u800c\u4e14\u6bcf\u8c03\u7528\u4e00\u6b21\u624d\u80fd\u751f\u6210\u4e00\u4e2a\u65b0\u5bf9\u8c61\u3002<\/p>\n<p>\u5982\u679c\u60f3\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u7ed9 lua \u589e\u52a0\u4e00\u79cd\u80fd\u529b\uff1a\u53ef\u4ee5\u6839\u636e\u4e00\u4e2a\u51fd\u6570\u7684 prototype \u6765\u76f4\u63a5\u6784\u5efa\u51fa function \u5bf9\u8c61\u3002<\/p>\n<p>prototype \u662f lua \u5185\u90e8\u7684\u4e00\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u6210\u4e00\u4e2a\u51fd\u6570\u53bb\u6389 upvalue \u540e\u7684\u90e8\u5206\u3002\u5f53\u4f60\u5199\uff1a<\/p>\n<pre>function foo(a)\r\n  return function()\r\n    return a\r\n  end\r\nend\r\n<\/pre>\n<p>\u65f6\uff0c\u6bcf\u6b21\u5bf9 foo(a) \u7684\u8c03\u7528\u90fd\u4f1a\u751f\u6210\u4e00\u4e2a\u4e0d\u540c\u7684\u533f\u540d\u51fd\u6570\u5bf9\u8c61\uff0c\u5b83\u4eec\u5f15\u7528\u7684 a \u90fd\u662f\u4e0d\u540c\u7684\uff08\u6bcf\u4e2a\u5206\u522b\u6307\u5411\u4e0d\u540c\u7684 a \uff09\u3002\u4f46\u662f\u8fd9\u4e9b\u4e0d\u540c\u7684\u533f\u540d\u51fd\u6570\u5bf9\u8c61\u62e5\u6709\u76f8\u540c\u7684 prototype \u5bf9\u8c61\u3002<\/p>\n<p>\u5982\u679c\u4f7f\u7528 lua \u7684\u5185\u90e8 c api \u53ef\u4ee5\u5b9e\u73b0\u8fd9\u6837\u4e00\u7ec4 api \uff0c\u6839\u636e\u4e00\u4e2a\u51fd\u6570\u7684 prototype \u6765\u6784\u5efa\u65b0\u7684\u51fd\u6570\uff0c\u6784\u5efa\u7684\u51fd\u6570\u7684 upvalue \u5168\u90e8\u4e3a nil \uff0c\u4f46\u4f60\u53ef\u4ee5\u518d\u4f7f\u7528 debug.upvaluejoin \u6765\u8fde\u63a5\u5230\u6b63\u786e\u7684 upvalue \u4e0a\u3002<\/p>\n<pre>#include \r\n#include \r\n\r\n#include \r\n#include \r\n#include \r\n\r\nstatic int\r\nlclone(lua_State *L) {\r\n    if (!lua_isfunction(L, 1) || lua_iscfunction(L,1))\r\n        return luaL_error(L, \"Need lua function\");\r\n    const LClosure *c = lua_topointer(L,1);\r\n    int n = luaL_optinteger(L, 2, 0);\r\n    if (n &lt; 0 || n &gt; c-&gt;p-&gt;sizep)\r\n        return 0;\r\n    luaL_checkstack(L, 1, NULL);\r\n    Proto *p;\r\n    if (n==0) {\r\n        p = c-&gt;p;\r\n    } else {\r\n        p = c-&gt;p-&gt;p[n-1];\r\n    }\r\n\r\n    lua_lock(L);\r\n    LClosure *cl = luaF_newLclosure(L, p-&gt;sizeupvalues);\r\n    luaF_initupvals(L, cl);\r\n    cl-&gt;p = p;\r\n    setclLvalue(L, L-&gt;top++, cl);\r\n    lua_unlock(L);\r\n\r\n    return 1;\r\n}\r\n\r\nstatic int\r\nlproto(lua_State *L) {\r\n    if (!lua_isfunction(L, 1) || lua_iscfunction(L,1))\r\n        return 0;\r\n    const LClosure *c = lua_topointer(L,1);\r\n    lua_pushlightuserdata(L, c-&gt;p);\r\n    lua_pushinteger(L, c-&gt;p-&gt;sizep);\r\n    return 2;\r\n}\r\n\r\nint\r\nluaopen_clonefunc(lua_State *L) {\r\n    luaL_checkversion(L);\r\n    luaL_Reg l[] = {\r\n        { \"clone\", lclone },\r\n        { \"proto\", lproto },\r\n        { NULL, NULL },\r\n    };\r\n    luaL_newlib(L, l);\r\n    return 1;\r\n}\r\n<\/pre>\n<p>\u4ee5\u4e0a\uff0cclone \u8fd9\u4e2a api \u53ef\u4ee5\u63a5\u6536\u4e24\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u5fc5\u987b\u4e3a\u4e00\u4e2a lua function \uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a 0 \u65f6\uff0c\u590d\u5236\u81ea\u8eab\uff1b\u4e3a 1~n \u65f6\uff0c\u4ee5\u5185\u90e8\u5b9a\u4e49\u597d\u7684 prototype \u6765\u6784\u5efa\u65b0\u7684\u51fd\u6570\u526f\u672c\u3002<\/p>\n<p>proto \u53ef\u4ee5\u8fd4\u56de\u51fd\u6570\u7684\u5185\u90e8prototype \u7684\u6307\u9488\uff0c\u548c debug.upvalueid() \u7c7b\u4f3c\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5224\u65ad\u4e24\u4e2a\u4e0d\u540c\u7684\u51fd\u6570\u662f\u5426\u6709\u76f8\u540c\u7684 prototype \u3002<\/p>\n<p>\u6709\u4e86\u8fd9\u4e24\u4e2a\u65b0 api \u7684\u5e2e\u52a9\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5b8c\u5584\u524d\u9762\u7684 reload \u5e93\u4e86\u3002\u6211\u5c06\u5b9e\u73b0\u653e\u5728\u91cc proto \u8fd9\u4e2a\u5206\u652f\u4e0a\u3002\u540c\u65f6\u5e0c\u671b\u8fd9\u7ec4\u65b0\u7684 api \u53ef\u4ee5\u8fdb\u5165 lua \u4e0b\u4e2a\u7248\u672c\u7684\u6807\u51c6\u4e2d\u53bb\u3002<\/p>\n<hr \/>\n<p>\u5982\u679c\u53ea\u60f3\u66f4\u66ff\u51fd\u6570 prototype \uff0c\u5982\u679c\u6211\u4eec\u9650\u5236\u65b0\u8001\u6a21\u5757\u7684 prototype \u63a5\u53e3\u5fc5\u987b\u5b8c\u5168\u76f8\u540c\uff0c\u90a3\u4e48\u5229\u7528\u6211\u4e0a\u9762\u63d0\u4f9b\u7684 api \u53ef\u4ee5\u66f4\u7b80\u5355\u7684\u5b9e\u73b0\u66f4\u65b0\u3002\u89c1 proto \u5206\u652f\u4e0a\u7684 hardreload.lua \u3002<\/p>\n<\/div>\n<\/div>\n<p class=\"entry-footer\"><span class=\"post-footers\">\u4e91\u98ce \u63d0\u4ea4\u4e8e November 23, 2016 09:42 PM<\/span>\u00a0<span class=\"separator\">|<\/span>\u00a0<a class=\"permalink\" href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.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=\"c046849\"><\/a><\/p>\n<div id=\"comment-46849\" class=\"comment\">\n<div class=\"comment-content\">\n<p>sb<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: DDD | (13)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46849\">April 8, 2017 01:37 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046827\"><\/a><\/p>\n<div id=\"comment-46827\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u6211\u770b\u5230\u7f51\u4e0a\u5f88\u591a\u4f8b\u5b50\u90fd\u662f\u91cd\u65b0\u52a0\u8f7d\u6587\u4ef6\uff0c\u7136\u540e\u8ddf_G\u8fdb\u884c\u5bf9\u6bd4\u5904\u7406,\u8fd9\u6837\u505a\u6709\u4ec0\u4e48\u4e0d\u597d\u5417\uff1f<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: OK | (12)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46827\">March 27, 2017 05:47 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046674\"><\/a><\/p>\n<div id=\"comment-46674\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u662f\u6307\u8fd9\u79cd\u60c5\u51b5\u5417\uff1f<br \/>\nlocal count=1<br \/>\nfunction test.f()<br \/>\nlocal function()<br \/>\ncount = 2<br \/>\nend<br \/>\nend<br \/>\n\u7684\u786e\u662f\u5982\u679c\u8fd9\u79cd\u65b9\u5f0f\u4f20\u9012count\u51fa\u53bb\u5c31\u4f1a\u51fa\u95ee\u9898<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: asqbtcupid | (11)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46674\">November 25, 2016 06:45 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046673\"><\/a><\/p>\n<div id=\"comment-46673\" class=\"comment\">\n<div class=\"comment-content\">\n<p>@Cloud \u5173\u4e8elocal count\u548ctest.count\uff0c\u6211\u6ca1\u660e\u767d\uff0c\u6211\u7684\u673a\u5236\u662f\u4fdd\u8bc1Reload\u524d\u540e\uff0c\u9664\u4e86function\u7c7b\u578b\u7684\u4f1a\u53d8\uff0c\u522b\u7684\u503c\u90fd\u7ef4\u6301\u539f\u6837\uff0ctest.count\u548ccount\u662fnumber\u7c7b\u578b\u7684\uff0c\u4e5f\u5c31\u4fdd\u6301\u4e0d\u53d8\u4e86\uff0c\u95ee\u9898\u5728\u54ea\u91cc\u5462\uff1f\u80fd\u5426\u518d\u7ed9\u6211\u4e00\u4e2a\u5177\u4f53\u7684\u4f8b\u5b50\uff1f<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: asqbtcupid | (10)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46673\">November 25, 2016 06:32 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046672\"><\/a><\/p>\n<div id=\"comment-46672\" class=\"comment\">\n<div class=\"comment-content\">\n<p>5.1 \u6ca1\u6709 upvaluejoin \u662f\u4e00\u4e2a\u7f3a\u9677\uff0c\u4e0d\u8fc7\u53ef\u4ee5\u81ea\u5df1\u7ed9 lua \u52a0\u8fd9\u4e2a\u4e1c\u897f\u3002<\/p>\n<p>\u6bd4\u5982\u4f8b\u5b50\u91cc\u4f60\u53ef\u4ee5\u4f20\u9012 test.count \uff0c\u4f46\u662f\u5982\u679c\u76f4\u63a5\u5199 local count \u5c31\u778e\u4e86\u3002<\/p>\n<p>thread \u5e76\u4e0d\u6307\u4f60\u7684 coroutine \uff0cmainthread \u4e5f\u662f thread \u3002\u4ece\u5b8c\u5907\u6027\u6765\u8bf4\uff0c\u5c31\u662f\u8c03\u7528 reload \u7684\u5730\u65b9\u7684\u4e0a\u4e0b\u6587\u91cc\u7684 local \u53d8\u91cf\u662f\u9700\u8981\u4fee\u6539\u7684\u3002<\/p>\n<p>module \u7684 require \u8fc7\u7a0b\u7406\u8bba\u4e0a\u4ec0\u4e48\u90fd\u53ef\u4ee5\u505a\uff0c\u6240\u4ee5\u83b7\u5f97 module \u6240\u4ea7\u751f\u7684\u6240\u6709\u51fd\u6570\u7684\u65b9\u6cd5\u6709\u4e09\u4e2a\uff1a<\/p>\n<p>1. \u5728 reload \u524d\u62cd\u4e00\u4e2a\u5feb\u7167\uff0creload \u540e\u6bd4\u8f83\u5feb\u7167\u3002\u8fd9\u4e2a\u6210\u672c\u5f88\u9ad8\u3002<\/p>\n<p>2. \u6211\u7684\u5b9e\u73b0\u4e2d\u7528\u5230\u7684\u65b9\u6cd5\uff0c\u5728 reload \u524d\u5efa\u7acb\u4e00\u4e2a\u6c99\u76d2\u3002\u8ba9 reload \u8fc7\u7a0b\u4e0d\u8981\u6ea2\u51fa\u6c99\u76d2\u3002\u4e00\u65e6\u6709\u8fd9\u79cd\u60c5\u51b5\u81f3\u5c11\u8c03\u7528\u8005\u53ef\u4ee5\u77e5\u9053\u3002<\/p>\n<p>3. \u6211\u4e0a\u6587\u540e\u9762\u63d0\u5230\u7684\u65b9\u6cd5\uff0c\u6269\u5c55 lua \u53ef\u4ee5\u63d0\u53d6\u51fa\u4e00\u4e2a function \u4e2d\u6240\u6709\u7684 prototype \u3002<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: Cloud | (9)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46672\">November 25, 2016 05:56 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046671\"><\/a><\/p>\n<div id=\"comment-46671\" class=\"comment\">\n<div class=\"comment-content\">\n<p>@cloud\u975e\u5e38\u611f\u8c22\u53cd\u9988\uff0c\u6211\u4e00\u4e00\u89e3\u7b54\u4e00\u4e0b\uff1a<br \/>\n1.lua5.1\u6ca1\u6709upvaluejoin\u554a\uff0c\u6240\u4ee5\u6211\u662f\u901a\u8fc7\u540d\u5b57\u8bc6\u522b\u5e76\u62f7\u8d1dupvalue\u7684\uff0c\u5728gif\u4f8b\u5b50\u91cc\u5c31\u6709\u4e00\u4e2a\u6dfb\u52a0\u4e86function\u7c7b\u7684upvalue\uff0c\u53ef\u4ee5\u8fd0\u884c\u554a\uff0ctable\u7c7b\u7684upvalue\u4e5f\u53ef\u4ee5\u4fee\u6539\u7684\uff0c\u4e0d\u8fc7\u53ea\u6709\u9488\u5bf9\u51fd\u6570\u7684\u4fee\u6539\u624d\u4f1a\u751f\u6548\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u66f4\u65b0\u51fd\u6570\u903b\u8f91\u3002<br \/>\n2.\u8fd9\u4e2a\u95ee\u9898\u7684\u786e\u662f\u5b58\u5728\u7684\uff0c\u56e0\u4e3a\u6211\u4eec\u662f\u7528lua\u6765\u505a\u6e38\u620f\u4e0a\u7684\u903b\u8f91\uff0c\u6ca1\u6709\u7528\u5230userdata\u548cthread\u7684\u529f\u80fd\uff0c\u6240\u4ee5\u5c31\u5ffd\u7565\u4e86\uff0c\u8fd9\u90e8\u5206\u6211\u518d\u5c1d\u8bd5\u52a0\u4e0a\u3002<br \/>\n3.\u90a3\u8bf7\u95ee\u600e\u4e48\u6837\u624d\u80fd\u5f97\u5230\u4e00\u4e2amoudle\u76f8\u5173\u7684\u5168\u90e8\u7684\u51fd\u6570\u5462\uff1f\u6211\u4e5f\u904d\u5386\u4e86\u5b83\u7684\u5143\u8868\u4ee5\u53ca\u6240\u6709\u51fd\u6570\u7684upvalue\u4e86\u3002<\/p>\n<p>\u4e91\u98ce\u5927\u5927\u53ef\u5426\u7559\u4e2aQQ\uff1f\u6211\u60f3\u518d\u5411\u4f60\u8ba8\u6559\u4e00\u4e0b\u5177\u4f53\u7684\u95ee\u9898\uff0c\u8c22\u8c22\u3002<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: asqbtcupid | (8)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46671\">November 25, 2016 05:36 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046670\"><\/a><\/p>\n<div id=\"comment-46670\" class=\"comment\">\n<div class=\"comment-content\">\n<p>@lichking<\/p>\n<p>1. lua \u6709\u6bd4 C# \u5f3a\u7684\u591a\u7684\u53cd\u5c04\u673a\u5236\u3002<\/p>\n<p>2. lua \u7684 metatable \u53ef\u4ee5\u7528\u6765\u6784\u5efa\u6bd4 C# \u66f4\u5f3a\u7684\u8fd0\u884c\u65f6\u7c7b\u578b\u7cfb\u7edf\u3002<\/p>\n<p>3. \u5982\u679c\u9700\u8981\u9759\u6001\u7c7b\u578b\u5e2e\u52a9\u5f00\u53d1\u671f\u5206\u6790\uff0c\u53ef\u4ee5\u4f7f\u7528 typed lua \u3002<\/p>\n<p>4. lua \u548c C \u7684\u4ea4\u4e92\u6bd4 C# \u9ad8\u6548\u7684\u591a\uff0c\u6027\u80fd\u654f\u611f\u7684\u5730\u65b9\u53ef\u4ee5\u6bd4 C# \u66f4\u65b9\u4fbf\u7684\u7528 C \u5199\u3002\u800c\u4e00\u822c\u4e1a\u52a1\uff0c\u65e0\u8bba\u662f lua \u548c C# \u90fd\u4e0d\u4f1a\u5728\u6027\u80fd\u4e0a\u51fa\u95ee\u9898\u3002<\/p>\n<p>5. C# \u7684 gc \u5728\u5185\u5b58\u53d7\u9650\u73af\u5883\u57fa\u672c\u4e0d\u53ef\u63a7\uff0cmono \u73af\u5883\u66f4\u52a0\u4e25\u91cd\u3002<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: Cloud | (7)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46670\">November 25, 2016 05:25 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046669\"><\/a><\/p>\n<div id=\"comment-46669\" class=\"comment\">\n<div class=\"comment-content\">\n<p>@asqbtcupid<\/p>\n<p>\u4f60\u7684\u5b9e\u73b0\u6709\u51e0\u4e2a\u660e\u663e\u7684\u95ee\u9898\uff08\u6ca1\u6709\u4ed4\u7ec6\u770b\u53ef\u80fd\u7684\u6f5c\u5728\u95ee\u9898\uff09<\/p>\n<p>1. \u4e0d\u7528 upvaluejoin \u662f\u4e0d\u80fd\u5c06 upvalue \u5173\u8054\u5bf9\u7684\u3002\u53ea\u6709 upvalue \u662f table \u4e14\u8fd0\u884c\u65f6\u4e0d\u4f1a\u4fee\u6539 upvalue \u624d\u53ef\u4ee5\u6b63\u786e\u8fd0\u884c\u3002<\/p>\n<p>2. \u904d\u5386 VM \u4e0d\u5468\u5168\u3002\u6ca1\u6709\u904d\u5386 userdata \uff0c\u6ca1\u6709\u904d\u5386 thread \u8c03\u7528\u6808\u3002\u9488\u5bf9 5.1 \u6765\u8bf4\uff0c\u8fd8\u9700\u8981\u904d\u5386\u51fd\u6570\u7684 env \u3002<\/p>\n<p>3. \u7b80\u5355\u904d\u5386 module table \u662f\u4e0d\u80fd\u4fdd\u8bc1\u627e\u5230\u6240\u6709 module \u76f8\u5173\u7684\u51fd\u6570\u7684\u3002<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: Cloud | (6)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46669\">November 25, 2016 05:17 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046668\"><\/a><\/p>\n<div id=\"comment-46668\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u4e00\u5e74\u524d\u505a\u8fc7\u7c7b\u4f3c\u7684\u70ed\u66f4\u65b0\u673a\u5236\uff0c\u5f88\u597d\u7684\u8fd0\u7528\u5230\u516c\u53f8\u7684\u9879\u76ee\u4e0a\u4e86\uff0c\u6211\u4eec\u7684\u7ea6\u675f\u6bd4\u8f83\u7b80\u5355\uff0c\u5c31\u662f\u53ea\u66f4\u65b0\u51fd\u6570\uff0c\u4e0d\u66f4\u65b0\u9664\u51fd\u6570\u4ee5\u5916\u7684\u4e1c\u897f\u3002https:\/\/github.com\/asqbtcupid\/lua_hotupdate \u6709\u4e2a\u7b80\u5355\u7684GIF\u6f14\u793a\uff0c\u53ea\u7528\u5728lua5.1+windows\u4e0a\u3002<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: asqbtcupid | (5)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46668\">November 25, 2016 02:56 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046667\"><\/a><\/p>\n<div id=\"comment-46667\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u4e5f\u53ef\u4ee5\u8bf4\u4e00\u4e2a\u6ca1\u6709\u590d\u6742\u7c7b\u578b\u7cfb\u7edf\uff0c\u6ca1\u6709\u5143\u6570\u636e\u53cd\u5c04\uff0c\u800c\u4e14\u6027\u80fd\u6349\u6025\u7684\u8bed\u8a00\uff0c\u8c08\u4e0d\u4e0a\u9ad8\u7ea7\uff0c<br \/>\nC#\u5c31\u8bed\u8a00\u8bbe\u65bd\u6765\u8bf4\uff0c\u662f\u6bd4lua\u4e30\u5bcc\u5f97\u591a\uff0c\u662f\u4ece\u5de5\u7a0b\u51fa\u53d1\u975e\u5e38\u6709\u7528\u7684\u7279\u6027<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: lichking | (4)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46667\">November 24, 2016 05:30 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046666\"><\/a><\/p>\n<div id=\"comment-46666\" class=\"comment\">\n<div class=\"comment-content\">\n<p>to medky:<br \/>\n\u9996\u5148\u5047\u5b9a\u8fd9\u91cc\u8bf4\u7684&#8221;\u70ed\u66f4\u65b0&#8221;\u53ea\u662f\u4e3a\u4e86\u4e0d\u91cd\u65b0\u5b89\u88c5\u5e94\u7528\u7684\u66f4\u65b0,\u800c\u4e0d\u662f\u4e0d\u5f71\u54cd\u5f53\u524d\u8fd0\u884c\u72b6\u6001\u7684\u5b9e\u65f6\u66f4\u65b0.<br \/>\nC#\u5728ios\u672a\u8d8a\u72f1\u7684\u60c5\u51b5\u4e0b\u65e0\u6cd5\u70ed\u66f4\u65b0.\u8d8a\u72f1\u548c\u5b89\u5353\u5e73\u53f0\u867d\u7136\u53ef\u4ee5\u70ed\u66f4\u65b0,\u4f46\u5751\u4e5f\u5f88\u591a,unity\u7684\u4e00\u4e9b\u8d44\u6e90\u4e5f\u5047\u5b9a\u7a0b\u5e8f\u662f\u65e0\u6cd5\u66f4\u65b0\u7684,\u67d0\u4e9b\u7a0b\u5e8f\u4fee\u6539\u4f1a\u6ca1\u6cd5\u6b63\u5e38\u8dd1.<br \/>\n\u9664\u975e\u60f3\u529e\u6cd5\u89e3\u91ca\u6267\u884cC#\u4ee3\u7801\u6216\u5b57\u8282\u7801,\u8fd9\u4e0e\u628aLua\u7ffb\u8bd1\u6210C#\u672c\u8d28\u662f\u4e00\u6837\u7684.\u96be\u70b9\u5728\u4e8eC#\u8bed\u6cd5\u7279\u6027\u90fd\u5f88\u590d\u6742,\u5373\u4f7f\u6ca1\u6709Lua\u90a3\u4e48\u9ad8\u7ea7,\u4e5f\u5f88\u96be\u505a\u51c6\u786e\u7684\u7ffb\u8bd1,\u76ee\u524d\u4e5f\u6ca1\u6709\u770b\u5230\u5f88\u597d\u7684\u5f00\u6e90\u5b9e\u73b0.<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by:\u00a0<a href=\"http:\/\/tieba.baidu.com\/f?kw=dwing\" rel=\"nofollow\">dwing<\/a>\u00a0| (3)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46666\">November 24, 2016 02:45 PM<\/a><\/p>\n<\/div>\n<p><a id=\"c046665\"><\/a><\/p>\n<div id=\"comment-46665\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u5728\u6211\u770b\u6765 lua \u662f\u6bd4 C# \u9ad8\u7ea7\u7684\u8bed\u8a00 \ud83d\ude42<\/p>\n<p>\u4e00\u4e2a\u6ca1\u6709\u5b8c\u5907\u7684 coroutine \uff0cfunction \u4e0d\u662f first class , gc \u7ec6\u8282\u4e0d\u53ef\u63a7\u7684\u8bed\u8a00\u8c08\u4e0d\u4e0a\u9ad8\u7ea7\u3002<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: Cloud | (2)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46665\">November 24, 2016 11:51 AM<\/a><\/p>\n<\/div>\n<p><a id=\"c046664\"><\/a><\/p>\n<div id=\"comment-46664\" class=\"comment\">\n<div class=\"comment-content\">\n<p>\u4e2a\u4eba\u89c9\u5f97\u9879\u76ee\u5b8c\u5168\u53ef\u4ee5\u7528C#\u8fd9\u6837\u7684\u9ad8\u7ea7\u8bed\u8a00\u5b9e\u73b0\uff0c\u53d1\u5e03\u7684\u65f6\u5019\u5c06C#\u7f16\u8bd1\u6210lua\u5b57\u8282\u7801\u5c31\u53ef\u4ee5\u4e86\uff0c\u8fd9\u6837lua\u70ed\u66f4\u65b0\u7684\u4f18\u52bf\u548c\u9ad8\u7ea7\u8bed\u8a00\u7684\u62bd\u8c61\u80fd\u529b\u90fd\u6709\u4e86\uff0c\u4e0d\u8fc7\u771f\u8fd9\u6837\u505a\u4e86\u4f55\u4e0d\u76f4\u63a5\u7528C#\u7684\u5b57\u8282\u7801\u505a\u70ed\u66f4\u65b0\u5462\uff1f<\/p>\n<\/div>\n<p class=\"comment-footer\">Posted by: medky | (1)\u00a0<a href=\"https:\/\/blog.codingnow.com\/2016\/11\/lua_update.html#comment-46664\">November 24, 2016 11:01 AM<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u8ba9 lua \u505a\u5c3d\u91cf\u6b63\u786e\u7684\u70ed\u66f4\u65b0 \u5f88\u591a<\/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-1045","post","type-post","status-publish","format-standard","hentry","tag-02-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1045","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=1045"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1045\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=1045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=1045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=1045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}