{"id":2304,"date":"2025-10-31T05:00:00","date_gmt":"2025-10-30T21:00:00","guid":{"rendered":"https:\/\/www.zhiwanyuzhou.com\/?p=2304"},"modified":"2025-11-03T21:33:34","modified_gmt":"2025-11-03T13:33:34","slug":"lua%e5%ad%97%e8%8a%82%e7%a0%81%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.zhiwanyuzhou.com\/index.php\/2025\/10\/31\/lua%e5%ad%97%e8%8a%82%e7%a0%81%e8%a7%a3%e6%9e%90\/","title":{"rendered":"Lua\u5b57\u8282\u7801\u89e3\u6790"},"content":{"rendered":"\n<h2>\u4e00\u3001\u524d\u8a00<\/h2>\n\n\n\n<p>Lua\u4e0ePython\u4e00\u6837\uff0c\u53ef\u4ee5\u88ab\u5b9a\u4e49\u4e3a\u811a\u672c\u578b\u7684\u8bed\u8a00\uff0c\u4e0ePython\u751f\u6210pyc\u5b57\u8282\u7801\u4e00\u6837\uff0cLua\u7a0b\u5e8f\u4e5f\u6709\u81ea\u5df1\u7684\u5b57\u8282\u7801\u683c\u5f0fluac\u3002Lua\u7a0b\u5e8f\u5728\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u540e\uff0cLua\u865a\u62df\u673a\u73af\u5883\u4f1a\u5c06\u5176\u7f16\u8bd1\u4e3aLuac\u5b57\u8282\u7801\uff0c\u56e0\u6b64\uff0c\u52a0\u8f7d\u672c\u5730\u7684Luac\u5b57\u8282\u7801\u4e0eLua\u6e90\u7a0b\u5e8f\u4e00\u6837\uff0c\u5728\u5185\u5b58\u4e2d\u90fd\u662f\u7f16\u8bd1\u597d\u7684\u4e8c\u8fdb\u5236\u7ed3\u6784\u3002<\/p>\n\n\n\n<h2>\u4e8c\u3001\u751f\u6210\u5b57\u8282\u7801<\/h2>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u5148\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684lua\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code has-palette-color-4-color has-palette-color-8-background-color has-text-color has-background\"><code>print(\"hello world\")<\/code><\/pre>\n\n\n\n<p>\u4ee5Lua5.15\u7248\u672c\u4e3a\u4f8b\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210\u5b57\u8282\u7801\u6587\u4ef6\uff0c\u9ed8\u8ba4\u662f\u5b58\u5728debug\u4fe1\u606f\u7684\uff0c\u53ef\u4ee5\u52a0\u5165-s\u53c2\u6570\u53bb\u9664debug\u4fe1\u606f<\/p>\n\n\n\n<pre class=\"wp-block-code has-palette-color-4-color has-palette-color-8-background-color has-text-color has-background\"><code>$ luac -o hello.luac hello.lua<\/code><\/pre>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u5199\u4e00\u4e2alua\u811a\u672c\uff0c\u8bfb\u53d6hello.lua\u751f\u6210\u5bf9\u5e94\u7684\u5b57\u8282\u7801\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code has-palette-color-4-color has-palette-color-8-background-color has-text-color has-background\"><code>local func, err = loadfile(arg&#91;1])\nif not func then\n   error(\"\u7f16\u8bd1\u9519\u8bef: \" .. err)\nend\n    \n-- \u8f6c\u6362\u4e3a\u5b57\u8282\u7801\nlocal bytecode = string.dump(func)\n    \n-- \u4fdd\u5b58\u5b57\u8282\u7801\u6587\u4ef6\nlocal file = io.open(arg&#91;2], \"wb\")\nfile:write(bytecode)\nfile:close()<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528lua\u8c03\u7528luac\u6587\u4ef6\uff0c\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"385\" height=\"87\" src=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/10\/image.png\" alt=\"\" class=\"wp-image-2305\" srcset=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/10\/image.png?v=1761897315 385w, https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/10\/image-300x68.png?v=1761897315 300w\" sizes=\"(max-width: 385px) 100vw, 385px\" \/><\/figure>\n\n\n\n<h2>\u4e09\u3001\u6587\u4ef6\u7ed3\u6784<\/h2>\n\n\n\n<p>\u6211\u4eec\u4f7f\u7528hexdump\u5206\u522b\u4ee516\u8fdb\u5236\u7684\u683c\u5f0f\u6253\u5370luac\u5b57\u8282\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code has-palette-color-4-color has-palette-color-8-background-color has-text-color has-background\"><code>          00 01 02 03 04 05 06 07  08 09 0A 0B 0C 0D 0E 0F\n00000000  1b 4c 75 61 51 00 01 04  08 04 08 00 0b 00 00 00  |.LuaQ...........|\n00000010  00 00 00 00 40 68 65 6c  6c 6f 2e 6c 75 61 00 00  |....@hello.lua..|\n00000020  00 00 00 00 00 00 00 00  00 02 02 04 00 00 00 05  |................|\n00000030  00 00 00 41 40 00 00 1c  40 00 01 1e 00 80 00 02  |...A@...@.......|\n00000040  00 00 00 04 06 00 00 00  00 00 00 00 70 72 69 6e  |............prin|\n00000050  74 00 04 0c 00 00 00 00  00 00 00 68 65 6c 6c 6f  |t..........hello|\n00000060  20 77 6f 72 6c 64 00 00  00 00 00 04 00 00 00 01  | world..........|\n00000070  00 00 00 01 00 00 00 01  00 00 00 01 00 00 00 00  |................|\n00000080  00 00 00 00 00 00 00                              |.......|\n\n<\/code><\/pre>\n\n\n\n<p>\u5b57\u6bb5\u89e3\u6790\uff0c\u53c2\u8003\u6e90\u7801 src\/lundump.c\u7684LoadHeader\u3001LoadFunction\u51fd\u6570<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\u504f\u79fb<\/td><td>\u5927\u5c0f<\/td><td>\u503c<\/td><td>\u5b57\u6bb5\u540d<\/td><td>\u4f5c\u7528<\/td><\/tr><tr><td>0x00-0x03<\/td><td>4<\/td><td>\"\\x1BLua\"<\/td><td>signature<\/td><td>\u6807\u5fd7<\/td><\/tr><tr><td>0x04<\/td><td>1<\/td><td>0x51<\/td><td>version<\/td><td>\u7248\u672c5.1<\/td><\/tr><tr><td>0x05<\/td><td>1<\/td><td>0<\/td><td>format<\/td><td>\u6587\u4ef6\u7684\u683c\u5f0f\u6807\u8bc6<\/td><\/tr><tr><td>0x06<\/td><td>1<\/td><td>1<\/td><td>endian<\/td><td>1\u4e3a\u5c0f\u7aef\u5e8f\uff0c0\u4e3a\u5927\u7aef\u5e8f<\/td><\/tr><tr><td>0x07<\/td><td>1<\/td><td>4<\/td><td>size_int<\/td><td>int\u7c7b\u578b\u6240\u5360\u7684\u5b57\u8282\u5927\u5c0f<\/td><\/tr><tr><td>0x08<\/td><td>1<\/td><td>8<\/td><td>size_size_t<\/td><td>size_t\u7c7b\u578b\u6240\u5360\u7684\u5b57\u8282\u5927\u5c0f<\/td><\/tr><tr><td>0x09<\/td><td>1<\/td><td>4<\/td><td>size_Instruction<\/td><td>Luac\u5b57\u8282\u7801\u7684\u4ee3\u7801\u5757\u4e2d\uff0c\u4e00\u6761\u6307\u4ee4\u7684\u5927\u5c0f<\/td><\/tr><tr><td>0x0A<\/td><td>1<\/td><td>8<\/td><td>size_lua_Number<\/td><td>\u6807\u8bc6<strong>lua_Number<\/strong>\u7c7b\u578b\u7684\u6570\u636e\u5927\u5c0f\u7c7b\u578b\u80fd\u5426\u6b63\u5e38\u7684\u5de5\u4f5c<\/td><\/tr><tr><td>0x0B<\/td><td>1<\/td><td>0<\/td><td>lua_num_valid<\/td><td>\u5b57\u6bb5\u901a\u5e38\u4e3a0\uff0c\u7528\u6765\u786e\u5b9a<strong>lua_Number<\/strong>\u7c7b\u578b\u80fd\u5426\u6b63\u5e38\u7684\u5de5\u4f5c<\/td><\/tr><tr><td>0x0C-0x13<\/td><td>8<\/td><td>0x0B<\/td><td>source_size<\/td><td>\u6e90\u7801\u540d\u79f0\u5927\u5c0f<\/td><\/tr><tr><td>0x14-0x1E<\/td><td>0x0B<\/td><td>@hello.lua<\/td><td>source_name<\/td><td>\u6e90\u7801\u540d\u79f0<\/td><\/tr><tr><td>0x1F-0x22<\/td><td>4<\/td><td>0<\/td><td>linedefined<\/td><td>\u884c\u5b9a\u4e49<\/td><\/tr><tr><td>0x23-0x26<\/td><td>4<\/td><td>0<\/td><td>lastlinedefined<\/td><td><\/td><\/tr><tr><td>0x27<\/td><td>1<\/td><td>0<\/td><td>nups<\/td><td><\/td><\/tr><tr><td>0x28<\/td><td>1<\/td><td>0<\/td><td>numparams<\/td><td>\u51fd\u6570\u6709\u51e0\u4e2a\u53c2\u6570<\/td><\/tr><tr><td>0x29<\/td><td>1<\/td><td>2<\/td><td>is_vararg<\/td><td>\u53c2\u6570\u662f\u5426\u4e3a\u53ef\u53d8\u53c2\u6570\u5217\u8868<\/td><\/tr><tr><td>0x2A<\/td><td>1<\/td><td>2<\/td><td>maxstacksize<\/td><td>\u5f53\u524d\u51fd\u6570\u7684Lua\u6808\u5927\u5c0f<\/td><\/tr><tr><td>0x2B-0x2E<\/td><td>4<\/td><td>4<\/td><td>sizecode<\/td><td>\u6307\u4ee4Code\u6761\u6570\uff0c\u67094\u6761\u6307\u4ee4<\/td><\/tr><tr><td>0x2F-0x32<\/td><td>4<\/td><td>0x05 0x00 0x00 0x00<\/td><td><\/td><td>\u6307\u4ee41\uff1aGETGLOBAL<\/td><\/tr><tr><td>0x33-0x36<\/td><td>4<\/td><td>0x41 0x40 0x00 0x00<\/td><td><\/td><td>\u6307\u4ee42\uff1aLOADK<\/td><\/tr><tr><td>0x37-0x3A<\/td><td>4<\/td><td>0x1C 0x40 0x00 0x01<\/td><td><\/td><td>\u6307\u4ee43\uff1aCALL<\/td><\/tr><tr><td>0x3B-0x3E<\/td><td>4<\/td><td>0x1E 0x00 0x80 0x00<\/td><td><\/td><td>\u6307\u4ee44\uff1aRETURN<\/td><\/tr><tr><td>0x3F-0x42<\/td><td>4<\/td><td>2<\/td><td>sizek<\/td><td>\u5e38\u91cfConstants\u6761\u6570<\/td><\/tr><tr><td>0x43<\/td><td>1<\/td><td>0x04<\/td><td>const_type<\/td><td>0\uff1a\u7a7a\uff0c1\uff1a\u5e03\u5c14\u578b\uff0c3\uff1a\u6570\u5b57\uff0c4\uff1a\u5b57\u7b26\u4e32<\/td><\/tr><tr><td>0x44-0x4B<\/td><td>8<\/td><td>0x06<\/td><td>val<\/td><td>\u8fd9\u91cc\u662f\u5b57\u7b26\u4e32\u957f\u5ea6<\/td><\/tr><tr><td>0x4C-0x51<\/td><td>6<\/td><td>\"print\"<\/td><td><\/td><td>\u5b57\u7b26\u4e32\u4e3a\"print\"<\/td><\/tr><tr><td>0x52<\/td><td>1<\/td><td>0x04<\/td><td>const_type<\/td><td>0\uff1a\u7a7a\uff0c1\uff1a\u5e03\u5c14\u578b\uff0c3\uff1a\u6570\u5b57\uff0c4\uff1a\u5b57\u7b26\u4e32<\/td><\/tr><tr><td>0x53-0x5A<\/td><td>1<\/td><td>0x0C<\/td><td><\/td><td>\u8fd9\u91cc\u662f\u5b57\u7b26\u4e32\u957f\u5ea6<\/td><\/tr><tr><td>0x5B-0x66<\/td><td>0x0C<\/td><td>\"hello world\"<\/td><td><\/td><td>\u5b57\u7b26\u4e32\u4e3a\"hello world\"<\/td><\/tr><tr><td>0x67-0x6A<\/td><td>4<\/td><td>0<\/td><td>sizep<\/td><td>\u5b50\u51fd\u6570Protos\u6761\u6570\uff0c\u8fd9\u91cc\u4e3a\u7a7a\uff0c\u5982\u679c\u6709\u7684\u8bdd\u5c31\u7ee7\u7eed\u89e3\u6790<\/td><\/tr><tr><td>0x6B-0x6E<\/td><td>4<\/td><td>4<\/td><td>sizelineinfo<\/td><td>\u884c\u4fe1\u606f\u6761\u6570<\/td><\/tr><tr><td>0x6F-0x72<\/td><td>4<\/td><td>1<\/td><td>lineinfo<\/td><td>\u884c\u4fe1\u606f<\/td><\/tr><tr><td>0x73-0x76<\/td><td>4<\/td><td>1<\/td><td><\/td><td>\u884c\u4fe1\u606f<\/td><\/tr><tr><td>0x77-0x7A<\/td><td>4<\/td><td>1<\/td><td><\/td><td>\u884c\u4fe1\u606f<\/td><\/tr><tr><td>0x7B-0x7E<\/td><td>4<\/td><td>1<\/td><td><\/td><td>\u884c\u4fe1\u606f<\/td><\/tr><tr><td>0x7F-0x82<\/td><td>4<\/td><td>0<\/td><td>sizelocvars<\/td><td>\u5c40\u90e8\u53d8\u91cf\u4fe1\u606fLocVars\u6761\u6570\uff0c\u8fd9\u91cc\u4e3a\u7a7a\uff0c\u5982\u679c\u6709\u7684\u8bdd\u5c31\u7ee7\u7eed\u89e3\u6790<\/td><\/tr><tr><td>0x83-0x86<\/td><td>4<\/td><td>0<\/td><td>sizeupvalues<\/td><td>\u5c40\u90e8\u53d8\u91cf\u4fe1\u606fUpValueNames\u6761\u6570\uff0c\u8fd9\u91cc\u4e3a\u7a7a\uff0c\u5982\u679c\u6709\u7684\u8bdd\u5c31\u7ee7\u7eed\u89e3\u6790<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2>\u56db\u3001\u4ee3\u7801\u8fd8\u539f<\/h2>\n\n\n\n<p>\u53ef\u4ee5\u4f7f\u7528luac\u89e3\u6790luac\u5b57\u8282\u7801\uff0c\u5f97\u5230\u4e86\u7c7b\u4f3c\u6c47\u7f16\u7684\u4ee3\u7801<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"616\" height=\"228\" src=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-2.png\" alt=\"\" class=\"wp-image-2317\" srcset=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-2.png?v=1762108214 616w, https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-2-300x111.png?v=1762108214 300w\" sizes=\"(max-width: 616px) 100vw, 616px\" \/><\/figure>\n\n\n\n<p>\u5982\u679c\u8fd8\u8981\u8fd8\u539f\u4e3a\u4f2a\u4ee3\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528unluac\u3001luadec\u53cd\u7f16\u8bd1\u5668\uff0c\u4f46\u662f\u5982\u679cpython\u89e3\u91ca\u5668\u52a0\u4ee5\u4fee\u6539\u5b57\u8282\u7801\u5c31\u53ef\u80fd\u65e0\u6cd5\u89e3\u6790\u4e86\uff0c\u9700\u8981\u77e5\u9053\u4fee\u6539\u4e86\u4ec0\u4e48\uff0c\u7136\u540e\u5bf9\u5e94\u4fee\u6539\u4e00\u4e0b\u53cd\u7f16\u8bd1\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"726\" height=\"153\" src=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/10\/image-2.png\" alt=\"\" class=\"wp-image-2308\" srcset=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/10\/image-2.png?v=1761897848 726w, https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/10\/image-2-300x63.png?v=1761897848 300w\" sizes=\"(max-width: 726px) 100vw, 726px\" \/><\/figure>\n\n\n\n<p>\u5982\u679c\u9047\u5230\u4e86opcode\u987a\u5e8f\u4fee\u6539\u7684\u7a0b\u5e8f\uff0c\u9700\u8981\u627e\u5230liblua.so\u6587\u4ef6\u91cc\u9762\u7684\u6b63\u786e\u7684opcode\u987a\u5e8f\uff0c\u9996\u5148\u4f7f\u7528\u53cd\u7f16\u8bd1\u5de5\u5177\u5206\u6790liblua.so\uff0c\u627e\u5230\u201cMOVE\u201d\u7b49\u5b57\u7b26\u4e32\u6240\u5728\u7684\u5730\u65b9\uff0c\u5982\u679c\u627e\u4e0d\u5230\uff0c\u53ef\u4ee5\u7528\u5341\u516d\u8fdb\u5236\u5de5\u5177\u641c\u7d22\u4e4b\u540e\u5bf9\u5e94\u4e0a\u7a0b\u5e8f\u7684\u5730\u5740\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"919\" height=\"708\" src=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image.png\" alt=\"\" class=\"wp-image-2310\" srcset=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image.png?v=1762005932 919w, https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-300x231.png?v=1762005932 300w, https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-768x592.png?v=1762005932 768w\" sizes=\"(max-width: 919px) 100vw, 919px\" \/><\/figure>\n\n\n\n<p>\u4ea4\u53c9\u5f15\u7528\uff0c\u627e\u5230\u5b8c\u6574\u7684opcode\u5217\u8868\u987a\u5e8f<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"587\" height=\"748\" src=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-1.png\" alt=\"\" class=\"wp-image-2311\" srcset=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-1.png?v=1762006081 587w, https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-1-235x300.png?v=1762006081 235w\" sizes=\"(max-width: 587px) 100vw, 587px\" \/><\/figure>\n\n\n\n<p>\u5f53\u7136\u8fd8\u8981\u5bf9\u4e00\u4e0b\u5b9e\u9645\u7684\u5904\u7406\u4ee3\u7801opcode\u662f\u5426\u662f\u8fd9\u6837\u7684\uff0c\u641c\u7d22lua_call\uff0c\u627e\u5230\u91cc\u9762\u7684\u51fd\u6570luaV_execute(\u6709\u53ef\u80fd\u6ca1\u6709\u51fd\u6570\u540d\u79f0)\uff0c\u627e\u91cc\u9762\u7684switch\uff08\u5982\u679c\u663e\u793a\u4e0d\u51fa\u6765\uff0c\u53ef\u4ee5\u8bd5\u7740\u6362\u4e00\u4e2a\u53cd\u7f16\u8bd1\u5de5\u5177\uff09\uff0c\u5bf9\u5e94\u4e0b\u6bcf\u4e00\u4e2aopcode\u7684\u4ee3\u7801\u662f\u5426\u5bf9\u5e94\u4e0a\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"823\" height=\"332\" src=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-3.png\" alt=\"\" class=\"wp-image-2325\" srcset=\"https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-3.png?v=1762176743 823w, https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-3-300x121.png?v=1762176743 300w, https:\/\/www.zhiwanyuzhou.com\/wp-content\/uploads\/2025\/11\/image-3-768x310.png?v=1762176743 768w\" sizes=\"(max-width: 823px) 100vw, 823px\" \/><\/figure>\n\n\n\n<p>\u4fee\u6539lua\u6e90\u7801lua-5.1\/src\/lopcodes.c<\/p>\n\n\n\n<pre class=\"wp-block-code has-palette-color-4-color has-palette-color-8-background-color has-text-color has-background\"><code>const char *const luaP_opnames&#91;NUM_OPCODES+1] = {\n\"GETTABLE\",\"GETGLOBAL\",\"SETGLOBAL\",\"SETUPVAL\",\"SETTABLE\",\"NEWTABLE\",\"SELF\",\"LOADNIL\",\"LOADK\",\"LOADBOOL\",\"GETUPVAL\",\"LT\",\"LE\",\"EQ\",\"DIV\",\"MUL\",\"SUB\",\"ADD\",\"MOD\",\"POW\",\"UNM\",\"NOT\",\"LEN\",\"CONCAT\",\"JMP\",\"TEST\",\"TESTSET\",\"MOVE\",\"FORLOOP\",\"FORPREP\",\"TFORLOOP\",\"SETLIST\",\"CLOSE\",\"CLOSURE\",\"CALL\",\"RETURN\",\"TAILCALL\",\"VARARG\",NULL};\n\nconst lu_byte luaP_opmodes&#91;NUM_OPCODES] = {\n\/*       T  A    B       C     mode\t\t   opcode\t*\/\nopmode(0, 1, OpArgR, OpArgK, iABC)\t\t\/* OP_GETTABLE *\/\n,opmode(0, 1, OpArgK, OpArgN, iABx)\t\t\/* OP_GETGLOBAL *\/\n,opmode(0, 0, OpArgK, OpArgN, iABx)\t\t\/* OP_SETGLOBAL *\/\n,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t\/* OP_SETUPVAL *\/\n,opmode(0, 0, OpArgK, OpArgK, iABC)\t\t\/* OP_SETTABLE *\/\n,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t\/* OP_NEWTABLE *\/\n,opmode(0, 1, OpArgR, OpArgK, iABC)\t\t\/* OP_SELF *\/\n,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t\/* OP_LOADNIL *\/\n,opmode(0, 1, OpArgK, OpArgN, iABx)\t\t\/* OP_LOADK *\/\n,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t\/* OP_LOADBOOL *\/\n,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t\/* OP_GETUPVAL *\/\n,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t\/* OP_LT *\/\n,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t\/* OP_LE *\/\n,opmode(1, 0, OpArgK, OpArgK, iABC)\t\t\/* OP_EQ *\/\n,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t\/* OP_DIV *\/\n,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t\/* OP_MUL *\/\n,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t\/* OP_SUB *\/\n,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t\/* OP_ADD *\/\n,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t\/* OP_MOD *\/\n,opmode(0, 1, OpArgK, OpArgK, iABC)\t\t\/* OP_POW *\/\n,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t\/* OP_UNM *\/\n,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t\/* OP_NOT *\/\n,opmode(0, 1, OpArgR, OpArgN, iABC)\t\t\/* OP_LEN *\/\n,opmode(0, 1, OpArgR, OpArgR, iABC)\t\t\/* OP_CONCAT *\/\n,opmode(0, 0, OpArgR, OpArgN, iAsBx)\t\t\/* OP_JMP *\/\n,opmode(1, 1, OpArgR, OpArgU, iABC)\t\t\/* OP_TEST *\/\n,opmode(1, 1, OpArgR, OpArgU, iABC)\t\t\/* OP_TESTSET *\/\n,opmode(0, 1, OpArgR, OpArgN, iABC) \t\t\/* OP_MOVE *\/\n,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t\/* OP_FORLOOP *\/\n,opmode(0, 1, OpArgR, OpArgN, iAsBx)\t\t\/* OP_FORPREP *\/\n,opmode(1, 0, OpArgN, OpArgU, iABC)\t\t\/* OP_TFORLOOP *\/\n,opmode(0, 0, OpArgU, OpArgU, iABC)\t\t\/* OP_SETLIST *\/\n,opmode(0, 0, OpArgN, OpArgN, iABC)\t\t\/* OP_CLOSE *\/\n,opmode(0, 1, OpArgU, OpArgN, iABx)\t\t\/* OP_CLOSURE *\/\n,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t\/* OP_CALL *\/\n,opmode(0, 0, OpArgU, OpArgN, iABC)\t\t\/* OP_RETURN *\/\n,opmode(0, 1, OpArgU, OpArgU, iABC)\t\t\/* OP_TAILCALL *\/\n,opmode(0, 1, OpArgU, OpArgN, iABC)\t\t\/* OP_VARARG *\/\n};<\/code><\/pre>\n\n\n\n<p>\u518d\u4fee\u6539lua-5.1\/src\/lopcodes.h<\/p>\n\n\n\n<pre class=\"wp-block-code has-palette-color-4-color has-palette-color-8-background-color has-text-color has-background\"><code>typedef enum {\n\/*----------------------------------------------------------------------\nname\t\targs\tdescription\n------------------------------------------------------------------------*\/\nOP_GETTABLE,\/*\tA B C\tR(A) := R(B)&#91;RK(C)]\t\t\t\t*\/\nOP_GETGLOBAL,\/*\tA Bx\tR(A) := Gbl&#91;Kst(Bx)]\t\t\t\t*\/\nOP_SETGLOBAL,\/*\tA Bx\tGbl&#91;Kst(Bx)] := R(A)\t\t\t\t*\/\nOP_SETUPVAL,\/*\tA B\tUpValue&#91;B] := R(A)\t\t\t\t*\/\nOP_SETTABLE,\/*\tA B C\tR(A)&#91;RK(B)] := RK(C)\t\t\t\t*\/\nOP_NEWTABLE,\/*\tA B C\tR(A) := {} (size = B,C)\t\t\t\t*\/\nOP_SELF,\/*\tA B C\tR(A+1) := R(B); R(A) := R(B)&#91;RK(C)]\t\t*\/\nOP_LOADNIL,\/*\tA B\tR(A) := ... := R(B) := nil\t\t\t*\/\nOP_LOADK,\/*\tA Bx\tR(A) := Kst(Bx)\t\t\t\t\t*\/\nOP_LOADBOOL,\/*\tA B C\tR(A) := (Bool)B; if (C) pc++\t\t\t*\/\nOP_GETUPVAL,\/*\tA B\tR(A) := UpValue&#91;B]\t\t\t\t*\/\nOP_LT,\/*\tA B C\tif ((RK(B) &lt;  RK(C)) ~= A) then pc++  \t\t*\/\nOP_LE,\/*\tA B C\tif ((RK(B) &lt;= RK(C)) ~= A) then pc++  \t\t*\/\nOP_EQ,\/*\tA B C\tif ((RK(B) == RK(C)) ~= A) then pc++\t\t*\/\nOP_DIV,\/*\tA B C\tR(A) := RK(B) \/ RK(C)\t\t\t\t*\/\nOP_MUL,\/*\tA B C\tR(A) := RK(B) * RK(C)\t\t\t\t*\/\nOP_SUB,\/*\tA B C\tR(A) := RK(B) - RK(C)\t\t\t\t*\/\nOP_ADD,\/*\tA B C\tR(A) := RK(B) + RK(C)\t\t\t\t*\/\nOP_MOD,\/*\tA B C\tR(A) := RK(B) % RK(C)\t\t\t\t*\/\nOP_POW,\/*\tA B C\tR(A) := RK(B) ^ RK(C)\t\t\t\t*\/\nOP_UNM,\/*\tA B\tR(A) := -R(B)\t\t\t\t\t*\/\nOP_NOT,\/*\tA B\tR(A) := not R(B)\t\t\t\t*\/\nOP_LEN,\/*\tA B\tR(A) := length of R(B)\t\t\t\t*\/\nOP_CONCAT,\/*\tA B C\tR(A) := R(B).. ... ..R(C)\t\t\t*\/\nOP_JMP,\/*\tsBx\tpc+=sBx\t\t\t\t\t*\/\nOP_TEST,\/*\tA C\tif not (R(A) &lt;=&gt; C) then pc++\t\t\t*\/ \nOP_TESTSET,\/*\tA B C\tif (R(B) &lt;=&gt; C) then R(A) := R(B) else pc++\t*\/ \nOP_MOVE,\/*\tA B\tR(A) := R(B)\t\t\t\t\t*\/\nOP_FORLOOP,\/*\tA sBx\tR(A)+=R(A+2);\n\t\t\tif R(A) &lt;?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*\/\nOP_FORPREP,\/*\tA sBx\tR(A)-=R(A+2); pc+=sBx\t\t\t\t*\/\nOP_TFORLOOP,\/*\tA C\tR(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); \n                     if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++\t*\/ \nOP_SETLIST,\/*\tA B C\tR(A)&#91;(C-1)*FPF+i] := R(A+i), 1 &lt;= i &lt;= B\t*\/\nOP_CLOSE,\/*\tA \tclose all variables in the stack up to (&gt;=) R(A)*\/\nOP_CLOSURE,\/*\tA Bx\tR(A) := closure(KPROTO&#91;Bx], R(A), ... ,R(A+n))\t*\/\nOP_CALL,\/*\tA B C\tR(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) *\/\nOP_RETURN,\/*\tA B\treturn R(A), ... ,R(A+B-2)\t(see note)\t*\/\nOP_TAILCALL,\/*\tA B C\treturn R(A)(R(A+1), ... ,R(A+B-1))\t\t*\/\nOP_VARARG\/*\tA B\tR(A), R(A+1), ..., R(A+B-1) = vararg\t\t*\/\n} OpCode;<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\u7f16\u8bd1luadec\u5c31\u80fd\u53cd\u7f16\u8bd1\u4e86\uff0c\u5982\u679c\u8fd8\u6709\u95ee\u9898\uff0c\u5c31\u8c03\u8bd5\u67e5\u770b\u662f\u54ea\u91cc\u4fee\u6539\u4e86\u3002<\/p>\n\n\n\n<h2>\u4e94\u3001\u53c2\u8003\u6587\u6863<\/h2>\n\n\n\n<p><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/30094117\">https:\/\/zhuanlan.zhihu.com\/p\/30094117<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/678462349\">https:\/\/zhuanlan.zhihu.com\/p\/678462349<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u524d\u8a00 Lua\u4e0ePython\u4e00\u6837\uff0c\u53ef\u4ee5\u88ab\u5b9a\u4e49\u4e3a\u811a\u672c\u578b\u7684\u8bed\u8a00\uff0c\u4e0ePython\u751f\u6210pyc\u5b57\u8282\u7801\u4e00\u6837\uff0cLua\u7a0b\u5e8f\u4e5f\u6709\u81ea\u5df1\u7684\u5b57\u8282\u7801\u683c\u5f0fluac\u3002Lua\u7a0b\u5e8f\u5728\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u540e\uff0cLua\u865a\u62df\u673a\u73af\u5883\u4f1a\u5c06\u5176\u7f16\u8bd1\u4e3aLua\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":5}},"_links":{"self":[{"href":"https:\/\/www.zhiwanyuzhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2304"}],"collection":[{"href":"https:\/\/www.zhiwanyuzhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhiwanyuzhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhiwanyuzhou.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhiwanyuzhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=2304"}],"version-history":[{"count":13,"href":"https:\/\/www.zhiwanyuzhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2304\/revisions"}],"predecessor-version":[{"id":2326,"href":"https:\/\/www.zhiwanyuzhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2304\/revisions\/2326"}],"wp:attachment":[{"href":"https:\/\/www.zhiwanyuzhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=2304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhiwanyuzhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=2304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhiwanyuzhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=2304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}