{"id":217600,"date":"2021-05-17T09:25:48","date_gmt":"2021-05-17T01:25:48","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=217600"},"modified":"2021-04-28T10:26:38","modified_gmt":"2021-04-28T02:26:38","slug":"linux-lua-teacher","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-lua-teacher.html","title":{"rendered":"\u6559\u4f60\u5982\u4f55\u7528 Lua \u64cd\u4f5c\u6587\u4ef6\u4e2d\u7684\u6570\u636e"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u4e86\u89e3 Lua \u5982\u4f55\u5904\u7406\u6570\u636e\u7684\u8bfb\u5199\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u6709\u4e9b\u6570\u636e\u662f\u4e34\u65f6\u7684\uff0c\u5b58\u50a8\u5728 RAM \u4e2d\uff0c\u53ea\u6709\u5728\u5e94\u7528\u8fd0\u884c\u65f6\u624d\u6709\u610f\u4e49\u3002\u4f46\u6709\u4e9b\u6570\u636e\u662f\u8981\u6301\u4e45\u7684\uff0c\u5b58\u50a8\u5728\u786c\u76d8\u4e0a\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002\u5f53\u4f60\u7f16\u7a0b\u65f6\uff0c\u65e0\u8bba\u662f\u7b80\u5355\u7684\u811a\u672c\u8fd8\u662f\u590d\u6742\u7684\u5de5\u5177\u5957\u4ef6\uff0c\u901a\u5e38\u90fd\u9700\u8981\u8bfb\u53d6\u548c\u5199\u5165\u6587\u4ef6\u3002\u6709\u65f6\u6587\u4ef6\u53ef\u80fd\u5305\u542b\u914d\u7f6e\u9009\u9879\uff0c\u800c\u53e6\u4e00\u4e9b\u65f6\u5019\u8fd9\u4e2a\u6587\u4ef6\u662f\u4f60\u7684\u7528\u6237\u7528\u4f60\u7684\u5e94\u7528\u521b\u5efa\u7684\u6570\u636e\u3002\u6bcf\u79cd\u8bed\u8a00\u90fd\u4f1a\u4ee5\u4e0d\u540c\u7684\u65b9\u5f0f\u5904\u7406\u8fd9\u9879\u4efb\u52a1\uff0c\u672c\u6587\u5c06\u6f14\u793a\u5982\u4f55\u4f7f\u7528 Lua \u5904\u7406\u6587\u4ef6\u6570\u636e\u3002<\/p>\n \u5b89\u88c5 Lua<\/strong><\/div>\n \u5982\u679c\u4f60\u4f7f\u7528\u7684\u662f Linux\uff0c\u4f60\u53ef\u4ee5\u4ece\u4f60\u7684\u53d1\u884c\u7248\u8f6f\u4ef6\u5e93\u4e2d\u5b89\u88c5 Lua\u3002\u5728 macOS \u4e0a\uff0c\u4f60\u53ef\u4ee5\u4ece MacPorts \u6216 Homebrew \u5b89\u88c5 Lua\u3002\u5728 Windows \u4e0a\uff0c\u4f60\u53ef\u4ee5\u4ece Chocolatey \u5b89\u88c5 Lua\u3002<\/p>\n \u5b89\u88c5 Lua \u540e\uff0c\u6253\u5f00\u4f60\u6700\u559c\u6b22\u7684\u6587\u672c\u7f16\u8f91\u5668\u5e76\u51c6\u5907\u5f00\u59cb\u3002<\/p>\n \u7528 Lua \u8bfb\u53d6\u6587\u4ef6<\/strong><\/div>\n Lua \u4f7f\u7528 io \u5e93\u8fdb\u884c\u6570\u636e\u8f93\u5165\u548c\u8f93\u51fa\u3002\u4e0b\u9762\u7684\u4f8b\u5b50\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a ingest \u7684\u51fd\u6570\u6765\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u7136\u540e\u7528 :read \u51fd\u6570\u8fdb\u884c\u89e3\u6790\u3002\u5728 Lua \u4e2d\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\u65f6\uff0c\u6709\u51e0\u79cd\u6a21\u5f0f\u53ef\u4ee5\u542f\u7528\u3002\u56e0\u4e3a\u6211\u53ea\u9700\u8981\u4ece\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u6240\u4ee5\u6211\u4f7f\u7528 r\uff08\u4ee3\u8868\u201c\u8bfb\u201d\uff09\u6a21\u5f0f\uff1a<\/p>\n \r\nfunction ingest(file)\r\n local f = io.open(file, \"r\")\r\n local lines = f:read(\"*all\")\r\n f:close()\r\n return(lines)\r\nend\r\nmyfile=ingest(\"example.txt\")\r\nprint(myfile)<\/pre>\n |