{"id":7374,"date":"2022-03-26T16:41:45","date_gmt":"2022-03-26T08:41:45","guid":{"rendered":"https:\/\/www.modbus.cn\/?p=7374"},"modified":"2026-07-01T00:42:53","modified_gmt":"2026-06-30T16:42:53","slug":"lua-ji-ben-yu-fa-shuo-ming","status":"publish","type":"post","link":"https:\/\/www.modbus.cn\/en\/7374.html","title":{"rendered":"LUA \u57fa\u672c\u8bed\u6cd5\u8bf4\u660e"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u672c\u7ae0\u8282\u4ecb\u7ecd\u7b80\u8981\u4ecb\u7ecd\u57fa\u672c\u7684lua\u8bed\u6cd5\uff0c\u6765\u81ea<a href=\"https:\/\/www.runoob.com\/lua\/lua-basic-syntax.html\" target=\"_blank\" rel=\"noopener noreferrer nofollow noreferrer noopener\">RUNOOB.COM<\/a>\u57fa\u7840\u6559\u5b66\uff0c\u5982\u6709\u95ee\u9898\uff0c\u8bf7\u8054\u7cfb\u5904\u7406<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lua \u7684\u8bed\u6cd5\u6bd4\u8f83\u7b80\u5355\uff0c\u6bd4\u8f83\u5bb9\u6613\u7406\u89e3\uff0c\u529f\u80fd\u5f3a\u5927\u3002\u6240\u4ee5\uff0c\u7b80\u5355\u7684\u5f52\u7eb3\u4e00\u4e0bLua\u7684\u4e00\u4e9b\u8bed\u6cd5\u89c4\u5219\uff0c\u5e2e\u52a9\u5feb\u901f\u5165\u95e8<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-\u6ce8\u91ca\">1 \u6ce8\u91ca<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"11-\u5355\u884c\u6ce8\u91ca\">1.1 \u5355\u884c\u6ce8\u91ca<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u603b\u662f\u5c11\u4e0d\u4e86\u6ce8\u91ca\u7684\u3002\u5728Lua\u4e2d\uff0c\u5355\u884c\u6ce8\u91ca\u4e2d\uff0c\u8fde\u7eed\u4e24\u4e2a\u51cf\u53f7&#8221;<strong>&#8212;<\/strong>&#8220;\u8868\u793a\u6ce8\u91ca\u7684\u5f00\u59cb\uff0c\u4e00\u76f4\u5ef6\u7eed\u5230\u884c\u672b\u4e3a\u6b62\u3002\u76f8\u5f53\u4e8eC\u3001C++\u8bed\u8a00\u4e2d\u7684&#8221;\/\/&#8221;\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---------- HTTP POST CHANGE PROJECT START ----------\nfunction on_http_finish_cb(key, value)\n\n    if key=='data' \n    then\n        -- do logical operations, user code\n        bell_cnt = 0\n    end\nend<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"12-\u591a\u884c\u6ce8\u91ca\u4e2d\">1.2 \u591a\u884c\u6ce8\u91ca\u4e2d<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531&#8221;&#8211;[[&#8220;\u8868\u793a\u6ce8\u91ca\u5f00\u59cb\uff0c\u5e76\u4e14\u4e00\u76f4\u5ef6\u7eed\u5230&#8221;&#8211;]]&#8221;\u4e3a\u6b62\u3002\u8fd9\u79cd\u6ce8\u91ca\u76f8\u5f53\u4e8eC\u8bed\u8a00\u4e2d\u7684&#8221;\/<em>&#8230;<\/em>\/&#8221;\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---------- HTTP POST CHANGE PROJECT START ----------\nfunction on_http_finish_cb(key, value)\n    if key=='data' \n    then\n    -- do logical operations, user code\n        bell_cnt = 0\n       --&#91;&#91; for i = sc_comeState, sc_bellFinsh\n        do\n            set_text(i, 3, '00 : 00')\n        end--]]\n    end\nend<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-\u8bed\u53e5\u5757\">2. \u8bed\u53e5\u5757<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bed\u53e5\u5757\u5728C\u4e2d\u662f\u7528&#8221;{&#8220;\u548c&#8221;}&#8221;\u62ec\u8d77\u6765\u7684\uff0c\u5728Lua\u4e2d\uff0c\u5b83\u662f\u7528do \u548c end \u62ec\u8d77\u6765\u7684\uff0cend\u8868\u793a\u6700\u8fd1\u4e00\u4e2a\u4ee3\u7801\u5757\u7684\u7ed3\u675f\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for i = 0, 10\ndo \n    print(\"Hello\") \nend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6216\u8005\u7528then\u548cend\u62ec\u8d77\u6765<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if 1 + 1 ==2\nthen \n    print(\"Hello\") \nend<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-\u53d8\u91cf\u7c7b\u578b\">3. \u53d8\u91cf\u7c7b\u578b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Lua \u662f\u52a8\u6001\u7c7b\u578b\u8bed\u8a00\uff0c\u6ca1\u6709\u7c7b\u578b\u5b9a\u4e49\uff08\u7c7b\u578b\u50cfC\uff0c\u6574\u5f62\u3001\u65e0\u7b26\u53f7\u3001\u5b57\u7b26\u7b49\u7b49\uff09,\u53ea\u9700\u8981\u4e3a\u53d8\u91cf\u8d4b\u503c\u3002 \u503c\u53ef\u4ee5\u5b58\u50a8\u5728\u53d8\u91cf\u4e2d\uff0c\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u6216\u7ed3\u679c\u8fd4\u56de\u3002Lua \u4e2d\u6709 8 \u4e2a\u57fa\u672c\u7c7b\u578b\u5206\u522b\u4e3a\uff1anil\u3001boolean\u3001number\u3001string\u3001userdata\u3001function\u3001thread \u548c table\uff0c\u5b9e\u9645\u5c4f\u5e55\u5e38\u7528\u7c7b\u578b\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><thead><tr><th>\u7c7b\u578b<\/th><th>\u63cf\u8ff0<\/th><\/tr><\/thead><tbody><tr><td>nil<\/td><td>\u8fd9\u4e2a\u6700\u7b80\u5355\uff0c\u53ea\u6709\u503cnil\u5c5e\u4e8e\u8be5\u7c7b\uff0c\u8868\u793a\u4e00\u4e2a\u65e0\u6548\u503c\uff08\u5728\u6761\u4ef6\u8868\u8fbe\u5f0f\u4e2d\u76f8\u5f53\u4e8efalse\uff09\uff0c\u5e94\u7528\u4e2d\u907f\u514d\u51fa\u73b0nil\u503c\uff0c\u9700\u8981\u505a\u975e\u6cd5\u5224\u65ad<\/td><\/tr><tr><td>number<\/td><td>\u5c4f\u5e55\u7684MCU\u4e3a32\u4f4d\uff0c\u5b9e\u9645\u5c4f\u5e55\u5e94\u7528\u4e2d\uff0c\u8d4b\u503c\u7684\u6570\u503c\u76f8\u5f53\u4e0e\u957f\u6574\u5f62\u6216\u5355\u7cbe\u5ea6\u6d6e\u70b9\u578b<\/td><\/tr><tr><td>string<\/td><td>\u5b57\u7b26\u4e32\u7531\u4e00\u5bf9\u53cc\u5f15\u53f7\u6216\u5355\u5f15\u53f7\u6765\u8868\u793a<\/td><\/tr><tr><td>table<\/td><td>Lua \u4e2d\u7684\u8868\uff08table\uff09\u5176\u5b9e\u662f\u4e00\u4e2a&#8221;\u5173\u8054\u6570\u7ec4&#8221;\uff08associative arrays\uff09\uff0c\u6570\u7ec4\u7684\u7d22\u5f15\u53ef\u4ee5\u662f\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u6216\u8868\u7c7b\u578b\u3002\u5728 Lua \u91cc\uff0ctable \u7684\u521b\u5efa\u662f\u901a\u8fc7&#8221;\u6784\u9020\u8868\u8fbe\u5f0f&#8221;\u6765\u5b8c\u6210\uff0c\u6700\u7b80\u5355\u6784\u9020\u8868\u8fbe\u5f0f\u662f{}\uff0c\u7528\u6765\u521b\u5efa\u4e00\u4e2a\u7a7a\u8868<\/td><\/tr><tr><td>function<\/td><td>\u7531 C \u6216 Lua \u7f16\u5199\u7684\u51fd\u6570<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"31-nil\uff08\u7a7a\uff09\">3.1 nil\uff08\u7a7a\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">nil \u7c7b\u578b\u8868\u793a\u4e00\u79cd\u6ca1\u6709\u4efb\u4f55\u6709\u6548\u503c\uff0c\u5b83\u53ea\u6709\u4e00\u4e2a\u503c &#8212; nil\uff0c\u4f8b\u5982\u6253\u5370\u4e00\u4e2a\u6ca1\u6709\u8d4b\u503c\u7684\u53d8\u91cf\uff0c\u4fbf\u4f1a\u8f93\u51fa\u4e00\u4e2a nil \u503c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; print(type(a))\nnil\n&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fb9\u754c\u503c\u5224\u65ad\uff0c\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5f15\u7528\u7684\u53d8\u91cf\u9700\u8981\u6700\u597d\u8981\u5224\u65ad\u662f\u5426\u4e3a\u7a7a\uff0c\u6216\u9632\u6b62\u4e3a\u7a7a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if type(a) == 'nil'\nthen\n    \u2013-user code\nelse\n    -\u2013user code\nend<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"32-number\uff08\u6570\u5b57\uff09\">3.2 number\uff08\u6570\u5b57\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Lua \u9ed8\u8ba4\u53ea\u6709\u4e00\u79cd number \u7c7b\u578b &#8212; double\uff08\u53cc\u7cbe\u5ea6\uff09\uff0c<strong><em>\u4f46\u662f\u5c4f\u5e55\u7684MCU\u662f32\u4f4d\u5904\u7406\u5668\uff0c\u6240\u4ee5\uff0c\u5728\u5c4f\u5e55\u8fd0\u884c\u4e0b\u4ec5\u652f\u6301\u5355\u7cbe\u5ea6<\/em><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u51e0\u79cd\u5199\u6cd5\u90fd\u88ab\u770b\u4f5c\u662f number \u7c7b\u578b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>local a = 2\nlocal b = 2.2\nlocal c = 0.2\nlocal d = 0.2e-1\n\nprint(type(a))\nprint(type(b))\nprint(type(c))\nprint(type(d))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u5b9e\u4f8b\uff0c\u4ee5\u4e0a\u4ee3\u7801\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;number\n&gt;number\n&gt;number\n&gt;number\n&gt;&gt;number\n&gt;number<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"3-3-string\uff08\u5b57\u7b26\u4e32\uff09\">3. 3 string\uff08\u5b57\u7b26\u4e32\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b57\u7b26\u4e32\u7531\u4e00\u5bf9\u53cc\u5f15\u53f7\u6216\u5355\u5f15\u53f7\u6765\u8868\u793a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>local string1 = \"this is string1\"\nlocal string2 = 'this is string2'<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"34-table\uff08\u8868\uff09\">3.4 table\uff08\u8868\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u76f8\u5f53\u4e8eC\u91cc\u9762\u7684\u6570\u7ec4\uff0c\u5728 Lua \u91cc\uff0ctable \u7684\u521b\u5efa\u662f\u901a\u8fc7&#8221;\u6784\u9020\u8868\u8fbe\u5f0f&#8221;\u6765\u5b8c\u6210\uff0c\u6700\u7b80\u5355\u6784\u9020\u8868\u8fbe\u5f0f\u662f{}\uff0c\u7528\u6765\u521b\u5efa\u4e00\u4e2a\u7a7a\u8868\u3002\u4e5f\u53ef\u4ee5\u5728\u8868\u91cc\u6dfb\u52a0\u4e00\u4e9b\u6570\u636e\uff0c\u76f4\u63a5\u521d\u59cb\u5316\u8868\uff0c\u4e0b\u6807\u9ed8\u8ba4\u4ece1\u5f00\u59cb\uff0c\u8f93\u51fa\u6d4b\u8bd5\u5982\u4e0b\u6240\u793a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u521b\u5efa\u4e00\u4e2a\u7a7a\u7684 table\nlocal tbl1 = {}\n-- \u76f4\u63a5\u521d\u59cb\u8868\nlocal tbl2 = {\"apple\", \"pear\", \"orange\", \"grape\"}\nprint(tbl2&#91;0])\nprint(tbl2&#91;1])<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u5b9e\u4f8b\uff0c\u4ee5\u4e0a\u4ee3\u7801\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;nil --\u62a5\u9519\n&gt;apple<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9\u8868\u7684\u4e0b\u68070\u8d4b\u503c\uff0c\u5728\u8f93\u51fa\u624d\u6b63\u5e38<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u76f4\u63a5\u521d\u59cb\u8868\nlocal tbl2 = {\"apple\", \"pear\", \"orange\", \"grape\"}\ntbl2&#91;0] = \"banana\"\nprint(tbl2&#91;0])\nprint(tbl2&#91;1])<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u5b9e\u4f8b\uff0c\u4ee5\u4e0a\u4ee3\u7801\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;banana\n&gt;apple<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"35-function\uff08\u51fd\u6570\uff09\">3.5 function\uff08\u51fd\u6570\uff09<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 Lua \u4e2d\uff0c\u51fd\u6570\u5b9a\u4e49\u58f0\u660e\u5982\u4e0b\u6240\u793a\uff0c\u5fc5\u987b\u5b9a\u4e49\u5728\u88ab\u8c03\u7528\u8005\u4e0a\u9762<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- function_test.lua \u811a\u672c\u6587\u4ef6\nfunction factorial1(n)\n    if n == 0 \n    then\n        return 1\n    else\n        return n * factorial1(n - 1)\n    end\nend\n\nprint(factorial1(5))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u5b9e\u4f8b\uff0c\u4ee5\u4e0a\u4ee3\u7801\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;120\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-\u53d8\u91cf\u5b9a\u4e49\">4 \u53d8\u91cf\u5b9a\u4e49<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u53d8\u91cf\u5728\u4f7f\u7528\u524d\uff0c\u9700\u8981\u5728\u4ee3\u7801\u4e2d\u8fdb\u884c\u58f0\u660e\uff0c\u5373\u521b\u5efa\u8be5\u53d8\u91cf\uff0c\u53d8\u91cf\u7684\u9ed8\u8ba4\u503c\u5747\u4e3a nil<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5168\u5c40\u53d8\u91cf\uff1aLua \u4e2d\u7684\u53d8\u91cf\u5168\u662f\u5168\u5c40\u53d8\u91cf\uff0c\u90a3\u6015\u662f\u8bed\u53e5\u5757\u6216\u662f\u51fd\u6570\u91cc\uff0c\u9664\u975e\u7528 local \u663e\u5f0f\u58f0\u660e\u4e3a\u5c40\u90e8\u53d8\u91cf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c40\u90e8\u53d8\u91cf\uff1a\u4f5c\u7528\u57df\u4e3a\u4ece\u58f0\u660e\u4f4d\u7f6e\u5f00\u59cb\u5230\u6240\u5728\u8bed\u53e5\u5757\u7ed3\u675f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- test.lua \u6587\u4ef6\u811a\u672c\na = 5               -- \u5168\u5c40\u53d8\u91cf\nlocal b = 5         -- \u5c40\u90e8\u53d8\u91cf\n\nfunction joke()\n    c = 5           -- \u5168\u5c40\u53d8\u91cf\n    local d = 6     -- \u5c40\u90e8\u53d8\u91cf\nend\nprint(c,d)          --&gt; 5 nil\n\ndo\n    local a = 6     -- \u5c40\u90e8\u53d8\u91cf\n    b = 6           -- \u5bf9\u5c40\u90e8\u53d8\u91cf\u91cd\u65b0\u8d4b\u503c\n    print(a,b);     --&gt; 6 6\nend\nprint(a,b)          --&gt; 5 6<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5--\u63a7\u5236\u8bed\u53e5\">5 \u63a7\u5236\u8bed\u53e5<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"51-if\u5224\u8bfb\u8bed\u53e5\">5.1 if(\u5224\u8bfb\u8bed\u53e5)<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a7\u5236\u7ed3\u6784\u7684\u6761\u4ef6\u8868\u8fbe\u5f0f\u7ed3\u679c\u53ef\u4ee5\u662f\u4efb\u4f55\u503c\uff0cLua\u8ba4\u4e3afalse\u548cnil\u4e3a\u5047\uff0ctrue\u548c\u975enil\u4e3a\u771f\u3002\u8981\u6ce8\u610f\u7684\u662fLua\u4e2d 0 \u4e3a true\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>local a = 0\nif a == 0\nthen\n    print(\"a = 0\")\nelseif a &gt; 0 \nthen\n    print(\"a &gt; 0 \")\nelse\n    print(\"a &lt; 0 \")\nend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u5b9e\u4f8b\uff0c\u4ee5\u4e0a\u4ee3\u7801\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;a = 0\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>\u4e0d\u652f\u6301switch case \u8bed\u53e5<\/em><\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"52-while\u5faa\u73af\">5.2 while(\u5faa\u73af)<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6761\u4ef6\u4e3a true \u65f6\uff0c\u8ba9\u7a0b\u5e8f\u91cd\u590d\u5730\u6267\u884c\u67d0\u4e9b\u8bed\u53e5\u3002\u6267\u884c\u8bed\u53e5\u524d\u4f1a\u5148\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u4e3a true<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>local  a = 10\nwhile(a &gt; 0 )\ndo\n    a = a - 1\nend<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"53-for\u5faa\u73af\">5.3 for(\u5faa\u73af)<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Lua \u7f16\u7a0b\u8bed\u8a00\u4e2d\u6570\u503c for \u5faa\u73af\u8bed\u6cd5\u683c\u5f0f:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6570\u503cfor\u5faa\u73af<\/li><li>\u6cdb\u578bfor\u5faa\u73af<\/li><\/ul>\n\n\n\n<h6 class=\"wp-block-heading\" id=\"\u6570\u503cfor\u5faa\u73af\">\u6570\u503cfor\u5faa\u73af<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">Lua \u7f16\u7a0b\u8bed\u8a00\u4e2d\u6570\u503c for \u5faa\u73af\u8bed\u6cd5\u683c\u5f0f\uff0cvar \u4ece exp1 \u53d8\u5316\u5230 exp2\uff0c\u6bcf\u6b21\u53d8\u5316\u4ee5 exp3 \u4e3a\u6b65\u957f\u9012\u589e var\uff0c\u5e76\u6267\u884c\u4e00\u6b21&nbsp;<strong>&#8220;\u6267\u884c\u4f53&#8221;<\/strong>\u3002exp3 \u662f\u53ef\u9009\u7684\uff0c\u5982\u679c\u4e0d\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a1\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for var=exp1,exp2,exp3 do  \n    &lt;\u6267\u884c\u4f53&gt;  \nend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u4f8b\u5faa\u73af\u8f93\u51fa1-5\u6570\u503c:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for i=1,5 do\n    print(i)\nend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u5b9e\u4f8b\uff0c\u4ee5\u4e0a\u4ee3\u7801\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;1\n&gt;2\n&gt;3\n&gt;4\n&gt;5<\/code><\/pre>\n\n\n\n<h6 class=\"wp-block-heading\" id=\"\u6cdb\u578bfor\u5faa\u73af\">\u6cdb\u578bfor\u5faa\u73af<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u6cdb\u578b for \u5faa\u73af\u901a\u8fc7\u4e00\u4e2a\u8fed\u4ee3\u5668\u51fd\u6570\u6765\u904d\u5386\u6240\u6709\u503c\uff0c\u7c7b\u4f3c java \u4e2d\u7684 foreach \u8bed\u53e5\u3002Lua \u7f16\u7a0b\u8bed\u8a00\u4e2d\u6cdb\u578b for \u5faa\u73af\u8bed\u6cd5\u683c\u5f0f\u3002i\u662f\u6570\u7ec4\u7d22\u5f15\u503c\uff0cv\u662f\u5bf9\u5e94\u7d22\u5f15\u7684\u6570\u7ec4\u5143\u7d20\u503c\u3002ipairs\u662fLua\u63d0\u4f9b\u7684\u4e00\u4e2a\u8fed\u4ee3\u5668\u51fd\u6570\uff0c\u7528\u6765\u8fed\u4ee3\u6570\u7ec4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>--\u6253\u5370\u6570\u7ec4a\u7684\u6240\u6709\u503c  \na = {\"one\", \"two\", \"three\"}\nfor i, v in ipairs(a) do\n    print(i, v)\nend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u4f8b\u5faa\u73af\u6570\u7ec4 days<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>days = {\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"} \nfor i,v in ipairs(days) \ndo \n    print(v) \nend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;Sunday\n&gt;Monday\n&gt;Tuesday\n&gt;Wednesday\n&gt;Thursday\n&gt;Friday\n&gt;Saturday<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6-\u8fd0\u7b97\u7b26\">6 \u8fd0\u7b97\u7b26<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"61-\u7b97\u672f\u8fd0\u7b97\u7b26\">6.1 \u7b97\u672f\u8fd0\u7b97\u7b26<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u8868\u5217\u51fa\u4e86 Lua \u8bed\u8a00\u4e2d\u7684\u5e38\u7528\u7b97\u672f\u8fd0\u7b97\u7b26\uff0c\u8bbe\u5b9a A \u7684\u503c\u4e3a10\uff0cB \u7684\u503c\u4e3a 20\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><thead><tr><th>\u64cd\u4f5c\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><\/thead><tbody><tr><td>+<\/td><td>\u52a0\u6cd5<\/td><td>A + B \u8f93\u51fa\u7ed3\u679c 30<\/td><\/tr><tr><td>&#8211;<\/td><td>\u51cf\u6cd5<\/td><td>A &#8211; B \u8f93\u51fa\u7ed3\u679c -10<\/td><\/tr><tr><td>*<\/td><td>\u4e58\u6cd5<\/td><td>A * B \u8f93\u51fa\u7ed3\u679c 200<\/td><\/tr><tr><td>\/<\/td><td>\u9664\u6cd5<\/td><td>B \/ A \u8f93\u51fa\u7ed3\u679c 2<\/td><\/tr><tr><td>%<\/td><td>\u53d6\u4f59<\/td><td>B % A \u8f93\u51fa\u7ed3\u679c 0<\/td><\/tr><tr><td>^<\/td><td>\u4e58\u5e42<\/td><td>A^2 \u8f93\u51fa\u7ed3\u679c 100<\/td><\/tr><tr><td>&#8211;<\/td><td>\u8d1f\u53f7<\/td><td>-A \u8f93\u51fa\u7ed3\u679c -10<\/td><\/tr><tr><td>^<\/td><td>\u5f02\u5e38\u6216<\/td><td>A~B\u7ed3\u679c30<\/td><\/tr><tr><td>&amp;<\/td><td>\u4e0e<\/td><td>A&amp;B\u7ed3\u679c0<\/td><\/tr><tr><td>I<\/td><td>\u6216<\/td><td>AIB\u7ed3\u679c30<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u5b9e\u4f8b\u6765\u66f4\u52a0\u900f\u5f7b\u7684\u7406\u89e3\u7b97\u672f\u8fd0\u7b97\u7b26\u7684\u5e94\u7528\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 21\nb = 10\n\nc = a + b\nprint(\"Line 1 - c \u7684\u503c\u4e3a \"..c )\n\nc = a - b\nprint(\"Line 2 - c \u7684\u503c\u4e3a \"..c )\n\nc = a * b\nprint(\"Line 3 - c \u7684\u503c\u4e3a \"..c )\n\nc = a \/ b\nprint(\"Line 4 - c \u7684\u503c\u4e3a \"..c )\n\nc = a % b\nprint(\"Line 5 - c \u7684\u503c\u4e3a \"..c )\n\nc = a^2\nprint(\"Line 6 - c \u7684\u503c\u4e3a \"..c )\n\nc = -a\nprint(\"Line 7 - c \u7684\u503c\u4e3a \"..c )\n\nc = a~b\nprint(\"Line 8 - c \u7684\u503c\u4e3a \"..c )\n\nc = a&amp;b\nprint(\"Line 9 - c \u7684\u503c\u4e3a \"..c )\n\nc = a|b\nprint(\"Line 10 - c \u7684\u503c\u4e3a \"..c )<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;Line 1 - c \u7684\u503c\u4e3a     31\n&gt;Line 2 - c \u7684\u503c\u4e3a     11\n&gt;Line 3 - c \u7684\u503c\u4e3a     210\n&gt;Line 4 - c \u7684\u503c\u4e3a     2.1\n&gt;Line 5 - c \u7684\u503c\u4e3a     1\n&gt;Line 6 - c \u7684\u503c\u4e3a     441\n&gt;Line 7 - c \u7684\u503c\u4e3a     -21\n&gt;Line 6 - c \u7684\u503c\u4e3a     31\n&gt;Line 7 - c \u7684\u503c\u4e3a     0\n&gt;Line 7 - c \u7684\u503c\u4e3a     31<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"62-\u5173\u7cfb\u8fd0\u7b97\u7b26\">6.2 \u5173\u7cfb\u8fd0\u7b97\u7b26<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u8868\u5217\u51fa\u4e86 Lua \u8bed\u8a00\u4e2d\u7684\u5e38\u7528\u5173\u7cfb\u8fd0\u7b97\u7b26\uff0c\u8bbe\u5b9a A \u7684\u503c\u4e3a10\uff0cB \u7684\u503c\u4e3a 20\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><thead><tr><th>\u64cd\u4f5c\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><\/thead><tbody><tr><td>==<\/td><td>\u7b49\u4e8e\uff0c\u68c0\u6d4b\u4e24\u4e2a\u503c\u662f\u5426\u76f8\u7b49\uff0c\u76f8\u7b49\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false<\/td><td>(A == B) \u4e3a false\u3002<\/td><\/tr><tr><td>~=<\/td><td>\u4e0d\u7b49\u4e8e\uff0c\u68c0\u6d4b\u4e24\u4e2a\u503c\u662f\u5426\u76f8\u7b49\uff0c\u4e0d\u76f8\u7b49\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false<\/td><td>(A ~= B) \u4e3a true\u3002<\/td><\/tr><tr><td>&gt;<\/td><td>\u5927\u4e8e\uff0c\u5982\u679c\u5de6\u8fb9\u7684\u503c\u5927\u4e8e\u53f3\u8fb9\u7684\u503c\uff0c\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false<\/td><td>(A &gt; B) \u4e3a false\u3002<\/td><\/tr><tr><td>&lt;<\/td><td>\u5c0f\u4e8e\uff0c\u5982\u679c\u5de6\u8fb9\u7684\u503c\u5927\u4e8e\u53f3\u8fb9\u7684\u503c\uff0c\u8fd4\u56de false\uff0c\u5426\u5219\u8fd4\u56de true<\/td><td>(A &lt; B) \u4e3a true\u3002<\/td><\/tr><tr><td>&gt;=<\/td><td>\u5927\u4e8e\u7b49\u4e8e\uff0c\u5982\u679c\u5de6\u8fb9\u7684\u503c\u5927\u4e8e\u7b49\u4e8e\u53f3\u8fb9\u7684\u503c\uff0c\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false<\/td><td>(A &gt;= B) \u8fd4\u56de false\u3002<\/td><\/tr><tr><td>&lt;=<\/td><td>\u5c0f\u4e8e\u7b49\u4e8e\uff0c \u5982\u679c\u5de6\u8fb9\u7684\u503c\u5c0f\u4e8e\u7b49\u4e8e\u53f3\u8fb9\u7684\u503c\uff0c\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false<\/td><td>(A &lt;= B) \u8fd4\u56de true\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u5b9e\u4f8b\u6765\u66f4\u52a0\u900f\u5f7b\u7684\u7406\u89e3\u5173\u7cfb\u8fd0\u7b97\u7b26\u7684\u5e94\u7528\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 21\nb = 10\n\nif( a == b )\nthen\n   print(\"Line 1 - a \u7b49\u4e8e b\" )\nelse\n   print(\"Line 1 - a \u4e0d\u7b49\u4e8e b\" )\nend\n\nif( a ~= b )\nthen\n   print(\"Line 2 - a \u4e0d\u7b49\u4e8e b\" )\nelse\n   print(\"Line 2 - a \u7b49\u4e8e b\" )\nend\n\nif ( a &lt; b )\nthen\n   print(\"Line 3 - a \u5c0f\u4e8e b\" )\nelse\n   print(\"Line 3 - a \u5927\u4e8e\u7b49\u4e8e b\" )\nend\n\nif ( a &gt; b )\nthen\n   print(\"Line 4 - a \u5927\u4e8e b\" )\nelse\n   print(\"Line 5 - a \u5c0f\u4e8e\u7b49\u4e8e b\" )\nend\n\n-- \u4fee\u6539 a \u548c b \u7684\u503c\na = 5\nb = 20\nif ( a &lt;= b )\nthen\n   print(\"Line 5 - a \u5c0f\u4e8e\u7b49\u4e8e  b\" )\nend\n\nif ( b &gt;= a )\nthen\n   print(\"Line 6 - b \u5927\u4e8e\u7b49\u4e8e a\" )\nend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;Line 1 - a \u4e0d\u7b49\u4e8e b\n&gt;Line 2 - a \u4e0d\u7b49\u4e8e b\n&gt;Line 3 - a \u5927\u4e8e\u7b49\u4e8e b\n&gt;Line 4 - a \u5927\u4e8e b\n&gt;Line 5 - a \u5c0f\u4e8e\u7b49\u4e8e  b\n&gt;Line 6 - b \u5927\u4e8e\u7b49\u4e8e a<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"63-\u903b\u8f91\u8fd0\u7b97\u7b26\">6.3 \u903b\u8f91\u8fd0\u7b97\u7b26<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u8868\u5217\u51fa\u4e86 Lua \u8bed\u8a00\u4e2d\u7684\u5e38\u7528\u903b\u8f91\u8fd0\u7b97\u7b26\uff0c\u8bbe\u5b9a A \u7684\u503c\u4e3a true\uff0cB \u7684\u503c\u4e3a false\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><thead><tr><th>\u64cd\u4f5c\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><\/thead><tbody><tr><td>and<\/td><td>\u903b\u8f91\u4e0e\u64cd\u4f5c\u7b26\u3002 \u82e5 A \u4e3a false\uff0c\u5219\u8fd4\u56de A\uff0c\u5426\u5219\u8fd4\u56de B\u3002<\/td><td>(A and B) \u4e3a false\u3002<\/td><\/tr><tr><td>or<\/td><td>\u903b\u8f91\u6216\u64cd\u4f5c\u7b26\u3002 \u82e5 A \u4e3a true\uff0c\u5219\u8fd4\u56de A\uff0c\u5426\u5219\u8fd4\u56de B\u3002<\/td><td>(A or B) \u4e3a true\u3002<\/td><\/tr><tr><td>not<\/td><td>\u903b\u8f91\u975e\u64cd\u4f5c\u7b26\u3002\u4e0e\u903b\u8f91\u8fd0\u7b97\u7ed3\u679c\u76f8\u53cd\uff0c\u5982\u679c\u6761\u4ef6\u4e3a true\uff0c\u903b\u8f91\u975e\u4e3a false\u3002<\/td><td>not(A and B) \u4e3a true\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u5b9e\u4f8b\u6765\u66f4\u52a0\u900f\u5f7b\u7684\u7406\u89e3\u903b\u8f91\u8fd0\u7b97\u7b26\u7684\u5e94\u7528\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = true\nb = true\n\nif ( a and b )\nthen\n   print(\"a and b - \u6761\u4ef6\u4e3a true\" )\nend\n\nif ( a or b )\nthen\n   print(\"a or b - \u6761\u4ef6\u4e3a true\" )\nend\n\nprint(\"---------\u5206\u5272\u7ebf---------\" )\n\n-- \u4fee\u6539 a \u548c b \u7684\u503c\na = false\nb = true\n\nif ( a and b )\nthen\n   print(\"a and b - \u6761\u4ef6\u4e3a true\" )\nelse\n   print(\"a and b - \u6761\u4ef6\u4e3a false\" )\nend\n\nif ( not( a and b) )\nthen\n   print(\"not( a and b) - \u6761\u4ef6\u4e3a true\" )\nelse\n   print(\"not( a and b) - \u6761\u4ef6\u4e3a false\" )\nend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;a and b - \u6761\u4ef6\u4e3a true\n&gt;a or b - \u6761\u4ef6\u4e3a true\n&gt;---------\u5206\u5272\u7ebf---------\n&gt;a and b - \u6761\u4ef6\u4e3a false\n&gt;not( a and b) - \u6761\u4ef6\u4e3a true<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"64-\u5176\u4ed6\u8fd0\u7b97\u7b26\">6.4 \u5176\u4ed6\u8fd0\u7b97\u7b26<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u8868\u5217\u51fa\u4e86 Lua \u8bed\u8a00\u4e2d\u7684\u8fde\u63a5\u8fd0\u7b97\u7b26\u4e0e\u8ba1\u7b97\u8868\u6216\u5b57\u7b26\u4e32\u957f\u5ea6\u7684\u8fd0\u7b97\u7b26\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><thead><tr><th>\u64cd\u4f5c\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><\/thead><tbody><tr><td>..<\/td><td>\u8fde\u63a5\u4e24\u4e2a\u5b57\u7b26\u4e32<\/td><td>a..b \uff0c\u5176\u4e2d a \u4e3a &#8220;Hello &#8221; \uff0c b \u4e3a &#8220;World&#8221;, \u8f93\u51fa\u7ed3\u679c\u4e3a &#8220;Hello World&#8221;\u3002<\/td><\/tr><tr><td>#<\/td><td>\u4e00\u5143\u8fd0\u7b97\u7b26\uff0c\u8fd4\u56de\u5b57\u7b26\u4e32\u6216\u8868\u7684\u957f\u5ea6\u3002<\/td><td>#&#8221;Hello&#8221; \u8fd4\u56de 5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u5b9e\u4f8b\u6765\u66f4\u52a0\u900f\u5f7b\u7684\u7406\u89e3\u8fde\u63a5\u8fd0\u7b97\u7b26\u4e0e\u8ba1\u7b97\u8868\u6216\u5b57\u7b26\u4e32\u957f\u5ea6\u7684\u8fd0\u7b97\u7b26\u7684\u5e94\u7528\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = \"Hello \"\nb = \"World\"\n\nprint(\"\u8fde\u63a5\u5b57\u7b26\u4e32 a \u548c b \", a..b )\nprint(\"b \u5b57\u7b26\u4e32\u957f\u5ea6 \",#b )\nprint(\"\u5b57\u7b26\u4e32 Test \u957f\u5ea6 \",#\"Test\" )\nprint(\"\u83dc\u9e1f\u6559\u7a0b\u7f51\u5740\u957f\u5ea6 \",#\"www.runoob.com\" )<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;\u8fde\u63a5\u5b57\u7b26\u4e32 a \u548c b     Hello World\n&gt;b \u5b57\u7b26\u4e32\u957f\u5ea6     5\n&gt;\u5b57\u7b26\u4e32 Test \u957f\u5ea6     4\n&gt;\u83dc\u9e1f\u6559\u7a0b\u7f51\u5740\u957f\u5ea6     14<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"65-\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\">6.5 \u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u9ad8\u5230\u4f4e\u7684\u987a\u5e8f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>^\nnot    - (unary)\n*      \/       %\n+      -\n..\n&lt;      &gt;      &lt;=     &gt;=     ~=     ==\nand\nor<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e86&nbsp;<strong>^<\/strong>&nbsp;\u548c&nbsp;<strong>..<\/strong>&nbsp;\u5916\u6240\u6709\u7684\u4e8c\u5143\u8fd0\u7b97\u7b26\u90fd\u662f\u5de6\u8fde\u63a5\u7684<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a+i &lt; b\/2+1          &lt;--&gt;       (a+i) &lt; ((b\/2)+1)\n5+x^2*8              &lt;--&gt;       5+((x^2)*8)\na &lt; y and y &lt;= z     &lt;--&gt;       (a &lt; y) and (y &lt;= z)\n-x^2                 &lt;--&gt;       -(x^2)\nx^y^z                &lt;--&gt;       x^(y^z)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u5b9e\u4f8b\u6765\u66f4\u52a0\u900f\u5f7b\u7684\u4e86\u89e3 Lua \u8bed\u8a00\u8fd0\u7b97\u7b26\u7684\u4f18\u5148\u7ea7\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 20\nb = 10\nc = 15\nd = 5\n\ne = (a + b) * c \/ d;*-- ( 30 \\* 15 ) \/ 5\nprint(\"(a + b) * c \/ d \u8fd0\u7b97\u503c\u4e3a  :\",e )\n\ne = ((a + b) * c) \/ d; *-- (30 \\* 15 ) \/ 5\nprint(\"((a + b) * c) \/ d \u8fd0\u7b97\u503c\u4e3a :\",e )\n\ne = (a + b) * (c \/ d);*-- (30) \\* (15\/5)\nprint(\"(a + b) * (c \/ d) \u8fd0\u7b97\u503c\u4e3a :\",e )\n\ne = a + (b * c) \/ d; *-- 20 + (150\/5)\nprint(\"a + (b * c) \/ d \u8fd0\u7b97\u503c\u4e3a  :\",e )<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;(a + b) * c \/ d \u8fd0\u7b97\u503c\u4e3a  :    90.0\n&gt;((a + b) * c) \/ d \u8fd0\u7b97\u503c\u4e3a :    90.0\n&gt;(a + b) * (c \/ d) \u8fd0\u7b97\u503c\u4e3a :    90.0\n&gt;a + (b * c) \/ d \u8fd0\u7b97\u503c\u4e3a   :    50.0<\/code><\/pre>\n<span id=\"magicpostMarker\"><\/span>","protected":false},"excerpt":{"rendered":"<p>\u672c\u7ae0\u8282\u4ecb\u7ecd\u7b80\u8981\u4ecb\u7ecd\u57fa\u672c\u7684lua\u8bed\u6cd5\uff0c\u6765\u81eaRUNOOB.COM&#8230;<\/p>","protected":false},"author":1,"featured_media":32741,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[3048,701],"tags":[731,730,627,732],"class_list":["post-7374","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-screen-lua-scripts","category-hmi-touchscreen","tag-lua","tag-lua-for","tag-627","tag-732"],"_links":{"self":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts\/7374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/comments?post=7374"}],"version-history":[{"count":0,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts\/7374\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/media\/32741"}],"wp:attachment":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/media?parent=7374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/categories?post=7374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/tags?post=7374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}