import{_ as n,c as s,o as a,a4 as t}from"./chunks/framework.Cy9JvDAg.js";const f=JSON.parse('{"title":"3.4.5 - 逻辑操作","description":"","frontmatter":{"title":"3.4.5 - 逻辑操作","footer":true,"lastUpdated":true,"outline":false},"headers":[],"relativePath":"3.4.5.md","filePath":"3.4.5.md"}'),o={name:"3.4.5.md"},r=t(`<h3 id="_3-4-5-逻辑操作" tabindex="-1">3.4.5 - 逻辑操作 <a class="header-anchor" href="#_3-4-5-逻辑操作" aria-label="Permalink to &quot;3.4.5 - 逻辑操作&quot;">​</a></h3><p>Lua中的逻辑操作就是<strong>and</strong>、<strong>or</strong>和<strong>not</strong>。与控制结构（参见<a href="/lua5.4-manual-zh/3.3.4.html">3.3.4</a>）类似，所有的逻辑操作将<strong>false</strong>和<strong>nil</strong>都视为假值而其他则视为真值。</p><p>取反操作<strong>not</strong>总是返回<strong>false</strong>或<strong>true</strong>。逻辑与操作<strong>and</strong>中，当第一个参数为<strong>false</strong>或<strong>nil</strong>时会将其返回；否则<strong>and</strong>返回第二个参数。逻辑或操作<strong>or</strong>中，当第一个参数的值不同于<strong>false</strong>或<strong>nil</strong>时会将其返回，否则<strong>or</strong>返回第二个参数。<strong>and</strong>和<strong>or</strong>都使用短路规则，第二个操作数只有在必要的时候才会被评估。这里是一些例子：</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>10 or 20            --&gt; 10</span></span>
<span class="line"><span>10 or error()       --&gt; 10</span></span>
<span class="line"><span>nil or &quot;a&quot;          --&gt; &quot;a&quot;</span></span>
<span class="line"><span>nil and 10          --&gt; nil</span></span>
<span class="line"><span>false and error()   --&gt; false</span></span>
<span class="line"><span>false and nil       --&gt; false</span></span>
<span class="line"><span>false or nil        --&gt; nil</span></span>
<span class="line"><span>10 and 20           --&gt; 20</span></span></code></pre></div>`,4),e=[r];function l(p,g,i,c,d,_){return a(),s("div",null,e)}const h=n(o,[["render",l]]);export{f as __pageData,h as default};
