import{_ as a,c as t,o as e,a4 as s}from"./chunks/framework.Cy9JvDAg.js";const m=JSON.parse('{"title":"3.3.7 - 局部声明","description":"","frontmatter":{"title":"3.3.7 - 局部声明","footer":true,"lastUpdated":true,"outline":false},"headers":[],"relativePath":"3.3.7.md","filePath":"3.3.7.md"}'),n={name:"3.3.7.md"},l=s(`<h3 id="_3-3-7-局部声明" tabindex="-1">3.3.7 - 局部声明 <a class="header-anchor" href="#_3-3-7-局部声明" aria-label="Permalink to &quot;3.3.7 - 局部声明&quot;">​</a></h3><p>局部变量可以声明在语法块中的任意位置。声明可以同时做初始化：</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>stat ::= local attnamelist [‘=’ explist]</span></span>
<span class="line"><span>attnamelist ::=  Name attrib {‘,’ Name attrib}</span></span></code></pre></div><p>如果有初始化赋值，则其语法与多重赋值一致（参见<a href="/lua5.4-manual-zh/3.3.3.html">3.3.3</a>）。否则，所有的变量都初始化为<strong>nil</strong>。</p><p>每个变量名后可以跟一个属性（一个在尖括号中的名称）：</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>attrib ::= [‘&lt;’ Name ‘&gt;’]</span></span></code></pre></div><p>属性有两种可能的值：const——声明一个常量；即一个不能在初始化后再次赋值的变量。close——声明一个待关闭变量（参见<a href="/lua5.4-manual-zh/3.3.8.html">3.3.8</a>）。</p><p>一个代码块也时一个语法块（参见<a href="/lua5.4-manual-zh/3.3.2.html">3.3.2</a>），因此也可以在显式语法块之外的代码块中声明局部变量。</p><p>局部变量的可见性规则解释可以参见<a href="/lua5.4-manual-zh/3.5.html">3.5</a>。</p>`,9),p=[l];function i(o,c,r,h,d,_){return e(),t("div",null,p)}const g=a(n,[["render",i]]);export{m as __pageData,g as default};
