import{_ as s,c as a,a as e,o as t}from"./app-C1vKFkGc.js";const p={};function l(i,n){return t(),a("div",null,[...n[0]||(n[0]=[e(`<h1 id="cmleonos-lua-api-文档" tabindex="-1"><a class="header-anchor" href="#cmleonos-lua-api-文档"><span>CMLeonOS Lua API 文档</span></a></h1><p>本文档记录了 CMLeonOS 中 Lua 支持的所有函数和库。</p><h2 id="基础库-base" tabindex="-1"><a class="header-anchor" href="#基础库-base"><span>基础库 (base)</span></a></h2><h3 id="assert-v-message" tabindex="-1"><a class="header-anchor" href="#assert-v-message"><span>assert(v [, message])</span></a></h3><p>如果 v 为 false 或 nil，则抛出错误。可选参数 message 为错误信息。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">assert</span><span class="token punctuation">(</span><span class="token keyword">true</span><span class="token punctuation">,</span> <span class="token string">&quot;This should be true&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">assert</span><span class="token punctuation">(</span><span class="token keyword">false</span><span class="token punctuation">,</span> <span class="token string">&quot;This is false&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="collectgarbage-opt" tabindex="-1"><a class="header-anchor" href="#collectgarbage-opt"><span>collectgarbage([opt])</span></a></h3><p>垃圾回收控制。支持以下选项：</p><ul><li><code>&quot;collect&quot;</code> - 执行垃圾回收</li><li><code>&quot;count&quot;</code> - 返回当前内存使用量（千字节）</li><li><code>&quot;step&quot;</code> - 执行一步垃圾回收</li><li><code>&quot;isrunning&quot;</code> - 返回垃圾回收器是否在运行</li></ul><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">collectgarbage</span><span class="token punctuation">(</span><span class="token string">&quot;collect&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">collectgarbage</span><span class="token punctuation">(</span><span class="token string">&quot;count&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="dofile-filename" tabindex="-1"><a class="header-anchor" href="#dofile-filename"><span>dofile([filename])</span></a></h3><p>加载并执行指定文件。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">dofile</span><span class="token punctuation">(</span><span class="token string">&quot;script.lua&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="input-prompt" tabindex="-1"><a class="header-anchor" href="#input-prompt"><span>input([prompt])</span></a></h3><p>从控制台读取一行输入。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> name <span class="token operator">=</span> <span class="token function">input</span><span class="token punctuation">(</span><span class="token string">&quot;Enter your name: &quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Hello, &quot;</span> <span class="token operator">..</span> name<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="error-message-level" tabindex="-1"><a class="header-anchor" href="#error-message-level"><span>error(message [, level])</span></a></h3><p>抛出错误并终止当前受保护的调用。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;Something went wrong&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="ipairs-t" tabindex="-1"><a class="header-anchor" href="#ipairs-t"><span>ipairs(t)</span></a></h3><p>遍历数组，返回迭代器函数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">for</span> i<span class="token punctuation">,</span> v <span class="token keyword">in</span> <span class="token function">ipairs</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span>
<span class="line">    <span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">,</span> v<span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="loadfile-filename" tabindex="-1"><a class="header-anchor" href="#loadfile-filename"><span>loadfile([filename])</span></a></h3><p>加载文件但不执行，返回函数或 nil, error。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> func<span class="token punctuation">,</span> err <span class="token operator">=</span> <span class="token function">loadfile</span><span class="token punctuation">(</span><span class="token string">&quot;script.lua&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">if</span> func <span class="token keyword">then</span></span>
<span class="line">    <span class="token function">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="load-string-chunkname" tabindex="-1"><a class="header-anchor" href="#load-string-chunkname"><span>load(string [, chunkname])</span></a></h3><p>加载字符串但不执行，返回函数或 nil, error。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> func <span class="token operator">=</span> <span class="token function">load</span><span class="token punctuation">(</span><span class="token string">&quot;print(&#39;Hello&#39;)&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">if</span> func <span class="token keyword">then</span></span>
<span class="line">    <span class="token function">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="loadstring-string-chunkname" tabindex="-1"><a class="header-anchor" href="#loadstring-string-chunkname"><span>loadstring(string [, chunkname])</span></a></h3><p>加载字符串但不执行，返回函数或 nil, error。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> func <span class="token operator">=</span> <span class="token function">loadstring</span><span class="token punctuation">(</span><span class="token string">&quot;print(&#39;Hello&#39;)&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">if</span> func <span class="token keyword">then</span></span>
<span class="line">    <span class="token function">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="next-table-index" tabindex="-1"><a class="header-anchor" href="#next-table-index"><span>next(table [, index])</span></a></h3><p>返回表的下一个键值对。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token punctuation">{</span>a <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> b <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">}</span></span>
<span class="line"><span class="token keyword">local</span> k<span class="token punctuation">,</span> v <span class="token operator">=</span> <span class="token function">next</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>k<span class="token punctuation">,</span> v<span class="token punctuation">)</span>  <span class="token comment">-- a, 1</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="pairs-t" tabindex="-1"><a class="header-anchor" href="#pairs-t"><span>pairs(t)</span></a></h3><p>遍历表，返回迭代器函数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token punctuation">{</span>x <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> y <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">,</span> z <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">}</span></span>
<span class="line"><span class="token keyword">for</span> k<span class="token punctuation">,</span> v <span class="token keyword">in</span> <span class="token function">pairs</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span> <span class="token keyword">do</span></span>
<span class="line">    <span class="token function">print</span><span class="token punctuation">(</span>k<span class="token punctuation">,</span> v<span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="pcall-f-arg1" tabindex="-1"><a class="header-anchor" href="#pcall-f-arg1"><span>pcall(f [, arg1, ...])</span></a></h3><p>安全调用函数，捕获错误。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> status<span class="token punctuation">,</span> err <span class="token operator">=</span> <span class="token function">pcall</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;Something went wrong&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">if</span> <span class="token keyword">not</span> status <span class="token keyword">then</span></span>
<span class="line">    <span class="token function">print</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="print" tabindex="-1"><a class="header-anchor" href="#print"><span>print(...)</span></a></h3><p>打印参数到控制台。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Hello, World!&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Value:&quot;</span><span class="token punctuation">,</span> <span class="token number">42</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="rawequal-v1-v2" tabindex="-1"><a class="header-anchor" href="#rawequal-v1-v2"><span>rawequal(v1, v2)</span></a></h3><p>比较两个值是否相等（不使用元方法）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">rawequal</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- true</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">rawequal</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- false</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="rawlen-v" tabindex="-1"><a class="header-anchor" href="#rawlen-v"><span>rawlen(v)</span></a></h3><p>返回值的长度（不使用元方法）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">rawlen</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 5</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="rawget-table-index" tabindex="-1"><a class="header-anchor" href="#rawget-table-index"><span>rawget(table, index)</span></a></h3><p>获取表的值（不使用元方法）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token function">setmetatable</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>__index <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token string">&quot;default&quot;</span> <span class="token keyword">end</span><span class="token punctuation">}</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">rawget</span><span class="token punctuation">(</span>t<span class="token punctuation">,</span> <span class="token string">&quot;key&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- default</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="rawset-table-index-value" tabindex="-1"><a class="header-anchor" href="#rawset-table-index-value"><span>rawset(table, index, value)</span></a></h3><p>设置表的值（不使用元方法）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span></span>
<span class="line"><span class="token function">rawset</span><span class="token punctuation">(</span>t<span class="token punctuation">,</span> <span class="token string">&quot;key&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;value&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="select-index" tabindex="-1"><a class="header-anchor" href="#select-index"><span>select(index, ...)</span></a></h3><p>返回第 index 个参数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">select</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">&quot;a&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;b&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;c&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- c</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="getmetatable-object" tabindex="-1"><a class="header-anchor" href="#getmetatable-object"><span>getmetatable(object)</span></a></h3><p>返回对象的元表。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span></span>
<span class="line">mt <span class="token operator">=</span> <span class="token punctuation">{</span>__add <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span> <span class="token keyword">return</span> a <span class="token operator">+</span> b <span class="token keyword">end</span><span class="token punctuation">}</span></span>
<span class="line"><span class="token function">setmetatable</span><span class="token punctuation">(</span>t<span class="token punctuation">,</span> mt<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">getmetatable</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span><span class="token punctuation">.</span>__add<span class="token punctuation">)</span>  <span class="token comment">-- function</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="setmetatable-table-metatable" tabindex="-1"><a class="header-anchor" href="#setmetatable-table-metatable"><span>setmetatable(table, metatable)</span></a></h3><p>设置对象的元表。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span></span>
<span class="line">mt <span class="token operator">=</span> <span class="token punctuation">{</span>__add <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span> <span class="token keyword">return</span> a <span class="token operator">+</span> b <span class="token keyword">end</span><span class="token punctuation">}</span></span>
<span class="line"><span class="token function">setmetatable</span><span class="token punctuation">(</span>t<span class="token punctuation">,</span> mt<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="tonumber-e-base" tabindex="-1"><a class="header-anchor" href="#tonumber-e-base"><span>tonumber(e [, base])</span></a></h3><p>将值转换为数字。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">tonumber</span><span class="token punctuation">(</span><span class="token string">&quot;123&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 123</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">tonumber</span><span class="token punctuation">(</span><span class="token string">&quot;FF&quot;</span><span class="token punctuation">,</span> <span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 255</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="tostring-v" tabindex="-1"><a class="header-anchor" href="#tostring-v"><span>tostring(v)</span></a></h3><p>将值转换为字符串。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">tostring</span><span class="token punctuation">(</span><span class="token number">123</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- &quot;123&quot;</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">tostring</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- &quot;table: 0x...&quot;</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="type-v" tabindex="-1"><a class="header-anchor" href="#type-v"><span>type(v)</span></a></h3><p>返回值的类型。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span><span class="token number">123</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- number</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- string</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- table</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span><span class="token keyword">nil</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- nil</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="xpcall-f-arg1" tabindex="-1"><a class="header-anchor" href="#xpcall-f-arg1"><span>xpcall(f [, arg1, ...])</span></a></h3><p>扩展的 pcall，返回状态和错误。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> ok<span class="token punctuation">,</span> err <span class="token operator">=</span> <span class="token function">xpcall</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token function">error</span><span class="token punctuation">(</span><span class="token string">&quot;Something went wrong&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">if</span> <span class="token keyword">not</span> ok <span class="token keyword">then</span></span>
<span class="line">    <span class="token function">print</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><hr><h2 id="数学库-math" tabindex="-1"><a class="header-anchor" href="#数学库-math"><span>数学库 (math)</span></a></h2><h3 id="math-abs-x" tabindex="-1"><a class="header-anchor" href="#math-abs-x"><span>math.abs(x)</span></a></h3><p>返回 x 的绝对值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">abs</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 5</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">abs</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>   <span class="token comment">-- 5</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-acos-x" tabindex="-1"><a class="header-anchor" href="#math-acos-x"><span>math.acos(x)</span></a></h3><p>返回 x 的反余弦值（弧度）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">acos</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 1.570796</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-asin-x" tabindex="-1"><a class="header-anchor" href="#math-asin-x"><span>math.asin(x)</span></a></h3><p>返回 x 的反正弦值（弧度）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">asin</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-atan2-y-x" tabindex="-1"><a class="header-anchor" href="#math-atan2-y-x"><span>math.atan2(y, x)</span></a></h3><p>返回 y/x 的反正切值（弧度）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">atan2</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-atan-x" tabindex="-1"><a class="header-anchor" href="#math-atan-x"><span>math.atan(x)</span></a></h3><p>返回 x 的反正切值（弧度）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">atan</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0.785398</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-ceil-x" tabindex="-1"><a class="header-anchor" href="#math-ceil-x"><span>math.ceil(x)</span></a></h3><p>返回不小于 x 的最小整数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">ceil</span><span class="token punctuation">(</span><span class="token number">3.5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 4</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">ceil</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">3.5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- -3</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-cosh-x" tabindex="-1"><a class="header-anchor" href="#math-cosh-x"><span>math.cosh(x)</span></a></h3><p>返回 x 的双曲余弦值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">cosh</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 1</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-cos-x" tabindex="-1"><a class="header-anchor" href="#math-cos-x"><span>math.cos(x)</span></a></h3><p>返回 x 的余弦值（弧度）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">cos</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 1</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">cos</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span>pi<span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- -1</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-deg-x" tabindex="-1"><a class="header-anchor" href="#math-deg-x"><span>math.deg(x)</span></a></h3><p>将弧度转换为角度。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">deg</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span>pi<span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 180</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-exp-x" tabindex="-1"><a class="header-anchor" href="#math-exp-x"><span>math.exp(x)</span></a></h3><p>返回 e 的 x 次方。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">exp</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 2.718282</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-floor-x" tabindex="-1"><a class="header-anchor" href="#math-floor-x"><span>math.floor(x)</span></a></h3><p>返回不大于 x 的最大整数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span><span class="token number">3.5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 3</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">3.5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- -4</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-fmod-x-y" tabindex="-1"><a class="header-anchor" href="#math-fmod-x-y"><span>math.fmod(x, y)</span></a></h3><p>返回 x 除以 y 的余数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">fmod</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 1</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-frexp-x" tabindex="-1"><a class="header-anchor" href="#math-frexp-x"><span>math.frexp(x)</span></a></h3><p>将 x 分解为尾数和指数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> m<span class="token punctuation">,</span> e <span class="token operator">=</span> math<span class="token punctuation">.</span><span class="token function">frexp</span><span class="token punctuation">(</span><span class="token number">1.5</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>m<span class="token punctuation">,</span> e<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-ldexp-m-e" tabindex="-1"><a class="header-anchor" href="#math-ldexp-m-e"><span>math.ldexp(m, e)</span></a></h3><p>返回 m 乘以 2 的 e 次方。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">ldexp</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 4</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-log10-x" tabindex="-1"><a class="header-anchor" href="#math-log10-x"><span>math.log10(x)</span></a></h3><p>返回 x 的以 10 为底的对数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">log10</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 2</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-log-x-base" tabindex="-1"><a class="header-anchor" href="#math-log-x-base"><span>math.log(x [, base])</span></a></h3><p>返回 x 的对数。默认以 e 为底。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 2.302585</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 2</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-max-x1" tabindex="-1"><a class="header-anchor" href="#math-max-x1"><span>math.max(x1, ...)</span></a></h3><p>返回参数中的最大值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">max</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 3</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">max</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- -1</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-min-x1" tabindex="-1"><a class="header-anchor" href="#math-min-x1"><span>math.min(x1, ...)</span></a></h3><p>返回参数中的最小值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 1</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- -5</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-modf-x" tabindex="-1"><a class="header-anchor" href="#math-modf-x"><span>math.modf(x)</span></a></h3><p>将 x 分解为整数和小数部分。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> i<span class="token punctuation">,</span> f <span class="token operator">=</span> math<span class="token punctuation">.</span><span class="token function">modf</span><span class="token punctuation">(</span><span class="token number">3.5</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">,</span> f<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-pow-x-y" tabindex="-1"><a class="header-anchor" href="#math-pow-x-y"><span>math.pow(x, y)</span></a></h3><p>返回 x 的 y 次方。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 8</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 100</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-rad-x" tabindex="-1"><a class="header-anchor" href="#math-rad-x"><span>math.rad(x)</span></a></h3><p>将角度转换为弧度。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">rad</span><span class="token punctuation">(</span><span class="token number">180</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 3.141593</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-random-m-n" tabindex="-1"><a class="header-anchor" href="#math-random-m-n"><span>math.random([m [, n]])</span></a></h3><p>返回随机数。无参数返回 [0,1)，一个参数返回 [1,m]，两个参数返回 [m,n]。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>      <span class="token comment">-- 0 或 1</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span>   <span class="token comment">-- 1-10</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 5-10</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-randomseed-x" tabindex="-1"><a class="header-anchor" href="#math-randomseed-x"><span>math.randomseed(x)</span></a></h3><p>设置随机数生成器的种子。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">math<span class="token punctuation">.</span><span class="token function">randomseed</span><span class="token punctuation">(</span>os<span class="token punctuation">.</span><span class="token function">time</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-sinh-x" tabindex="-1"><a class="header-anchor" href="#math-sinh-x"><span>math.sinh(x)</span></a></h3><p>返回 x 的双曲正弦值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">sinh</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-sin-x" tabindex="-1"><a class="header-anchor" href="#math-sin-x"><span>math.sin(x)</span></a></h3><p>返回 x 的正弦值（弧度）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">sin</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">sin</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span>pi<span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 1</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-sqrt-x" tabindex="-1"><a class="header-anchor" href="#math-sqrt-x"><span>math.sqrt(x)</span></a></h3><p>返回 x 的平方根。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">sqrt</span><span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 4</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">sqrt</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>   <span class="token comment">-- 1.414214</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-tanh-x" tabindex="-1"><a class="header-anchor" href="#math-tanh-x"><span>math.tanh(x)</span></a></h3><p>返回 x 的双曲正切值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">tanh</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-tan-x" tabindex="-1"><a class="header-anchor" href="#math-tan-x"><span>math.tan(x)</span></a></h3><p>返回 x 的正切值（弧度）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">tan</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span><span class="token function">tan</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span>pi<span class="token operator">/</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 1</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="math-pi" tabindex="-1"><a class="header-anchor" href="#math-pi"><span>math.pi</span></a></h3><p>圆周率常量。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span>pi<span class="token punctuation">)</span>  <span class="token comment">-- 3.141592653589793</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="math-huge" tabindex="-1"><a class="header-anchor" href="#math-huge"><span>math.huge</span></a></h3><p>表示最大数值的常量。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>math<span class="token punctuation">.</span>huge<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><hr><h2 id="字符串库-string" tabindex="-1"><a class="header-anchor" href="#字符串库-string"><span>字符串库 (string)</span></a></h2><h3 id="string-byte-s-i-j" tabindex="-1"><a class="header-anchor" href="#string-byte-s-i-j"><span>string.byte(s [, i [, j]])</span></a></h3><p>返回字符的内部数值表示。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">byte</span><span class="token punctuation">(</span><span class="token string">&quot;ABC&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 65</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">byte</span><span class="token punctuation">(</span><span class="token string">&quot;ABC&quot;</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 66</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">byte</span><span class="token punctuation">(</span><span class="token string">&quot;ABC&quot;</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 67</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="string-char" tabindex="-1"><a class="header-anchor" href="#string-char"><span>string.char(...)</span></a></h3><p>将数值转换为字符。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">char</span><span class="token punctuation">(</span><span class="token number">65</span><span class="token punctuation">,</span> <span class="token number">66</span><span class="token punctuation">,</span> <span class="token number">67</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- ABC</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="string-dump-function" tabindex="-1"><a class="header-anchor" href="#string-dump-function"><span>string.dump(function)</span></a></h3><p>返回函数的二进制表示。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">dump</span><span class="token punctuation">(</span>print<span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="string-find-s-pattern-init-plain" tabindex="-1"><a class="header-anchor" href="#string-find-s-pattern-init-plain"><span>string.find(s, pattern [, init [, plain]])</span></a></h3><p>在字符串中查找模式。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">&quot;hello world&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;world&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 7</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token string">&quot;hello world&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;l&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 3</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="string-format-formatstring" tabindex="-1"><a class="header-anchor" href="#string-format-formatstring"><span>string.format(formatstring, ...)</span></a></h3><p>格式化字符串。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token string">&quot;Value: %d&quot;</span><span class="token punctuation">,</span> <span class="token number">42</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token string">&quot;Name: %s, Age: %d&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;Alice&quot;</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="string-gmatch-s-pattern" tabindex="-1"><a class="header-anchor" href="#string-gmatch-s-pattern"><span>string.gmatch(s, pattern)</span></a></h3><p>返回字符串中所有匹配模式的迭代器。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">for</span> word <span class="token keyword">in</span> string<span class="token punctuation">.</span><span class="token function">gmatch</span><span class="token punctuation">(</span><span class="token string">&quot;hello world&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;%a+&quot;</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span>
<span class="line">    <span class="token function">print</span><span class="token punctuation">(</span>word<span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="string-gsub-s-pattern-repl-n" tabindex="-1"><a class="header-anchor" href="#string-gsub-s-pattern-repl-n"><span>string.gsub(s, pattern, repl [, n])</span></a></h3><p>替换字符串中的模式。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">gsub</span><span class="token punctuation">(</span><span class="token string">&quot;hello world&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;world&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;Lua&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- hello Lua</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">gsub</span><span class="token punctuation">(</span><span class="token string">&quot;hello world&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;l&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;L&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- HeLLo Lua</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="string-len-s" tabindex="-1"><a class="header-anchor" href="#string-len-s"><span>string.len(s)</span></a></h3><p>返回字符串长度。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">len</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 5</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="string-lower-s" tabindex="-1"><a class="header-anchor" href="#string-lower-s"><span>string.lower(s)</span></a></h3><p>将字符串转换为小写。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">lower</span><span class="token punctuation">(</span><span class="token string">&quot;HELLO&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- hello</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="string-match-s-pattern-init" tabindex="-1"><a class="header-anchor" href="#string-match-s-pattern-init"><span>string.match(s, pattern [, init])</span></a></h3><p>返回字符串中第一个匹配模式的子串。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span><span class="token string">&quot;hello world&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;%w+&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- hello</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="string-rep-s-n" tabindex="-1"><a class="header-anchor" href="#string-rep-s-n"><span>string.rep(s, n)</span></a></h3><p>重复字符串 n 次。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">rep</span><span class="token punctuation">(</span><span class="token string">&quot;ab&quot;</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- ababab</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="string-reverse-s" tabindex="-1"><a class="header-anchor" href="#string-reverse-s"><span>string.reverse(s)</span></a></h3><p>反转字符串。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">reverse</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- olleh</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="string-sub-s-i-j" tabindex="-1"><a class="header-anchor" href="#string-sub-s-i-j"><span>string.sub(s, i [, j])</span></a></h3><p>返回字符串的子串。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">sub</span><span class="token punctuation">(</span><span class="token string">&quot;hello world&quot;</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- hello</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">sub</span><span class="token punctuation">(</span><span class="token string">&quot;hello world&quot;</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- world</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="string-upper-s" tabindex="-1"><a class="header-anchor" href="#string-upper-s"><span>string.upper(s)</span></a></h3><p>将字符串转换为大写。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>string<span class="token punctuation">.</span><span class="token function">upper</span><span class="token punctuation">(</span><span class="token string">&quot;hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- HELLO</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><hr><h2 id="操作系统库-os" tabindex="-1"><a class="header-anchor" href="#操作系统库-os"><span>操作系统库 (os)</span></a></h2><h3 id="os-clock" tabindex="-1"><a class="header-anchor" href="#os-clock"><span>os.clock()</span></a></h3><p>返回程序使用的 CPU 时间（秒）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>os<span class="token punctuation">.</span><span class="token function">clock</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-gethostname" tabindex="-1"><a class="header-anchor" href="#os-gethostname"><span>os.gethostname()</span></a></h3><p>返回系统主机名。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>os<span class="token punctuation">.</span><span class="token function">gethostname</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-getenv-varname" tabindex="-1"><a class="header-anchor" href="#os-getenv-varname"><span>os.getenv(varname)</span></a></h3><p>返回环境变量的值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>os<span class="token punctuation">.</span><span class="token function">getenv</span><span class="token punctuation">(</span><span class="token string">&quot;PATH&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-setenv-varname-value" tabindex="-1"><a class="header-anchor" href="#os-setenv-varname-value"><span>os.setenv(varname, value)</span></a></h3><p>设置环境变量的值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">setenv</span><span class="token punctuation">(</span><span class="token string">&quot;MYVAR&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;value&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-delenv-varname" tabindex="-1"><a class="header-anchor" href="#os-delenv-varname"><span>os.delenv(varname)</span></a></h3><p>删除环境变量。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">delenv</span><span class="token punctuation">(</span><span class="token string">&quot;MYVAR&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-addenv-varname-value" tabindex="-1"><a class="header-anchor" href="#os-addenv-varname-value"><span>os.addenv(varname, value)</span></a></h3><p>添加环境变量（同 setenv）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">addenv</span><span class="token punctuation">(</span><span class="token string">&quot;MYVAR&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;value&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-execute-command" tabindex="-1"><a class="header-anchor" href="#os-execute-command"><span>os.execute(command)</span></a></h3><p>执行 Shell 命令。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">execute</span><span class="token punctuation">(</span><span class="token string">&quot;ls&quot;</span><span class="token punctuation">)</span></span>
<span class="line">os<span class="token punctuation">.</span><span class="token function">execute</span><span class="token punctuation">(</span><span class="token string">&quot;echo Hello&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="os-executefile-path" tabindex="-1"><a class="header-anchor" href="#os-executefile-path"><span>os.executefile(path)</span></a></h3><p>执行命令文件（.cm）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">executefile</span><span class="token punctuation">(</span><span class="token string">&quot;myscript.cm&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-reboot" tabindex="-1"><a class="header-anchor" href="#os-reboot"><span>os.reboot()</span></a></h3><p>重启系统。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">reboot</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-shutdown" tabindex="-1"><a class="header-anchor" href="#os-shutdown"><span>os.shutdown()</span></a></h3><p>关闭系统。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">shutdown</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-sleep-seconds" tabindex="-1"><a class="header-anchor" href="#os-sleep-seconds"><span>os.sleep(seconds)</span></a></h3><p>休眠指定秒数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">sleep</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-beep" tabindex="-1"><a class="header-anchor" href="#os-beep"><span>os.beep()</span></a></h3><p>发出蜂鸣声。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">beep</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-clear" tabindex="-1"><a class="header-anchor" href="#os-clear"><span>os.clear()</span></a></h3><p>清屏。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">clear</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-getusername" tabindex="-1"><a class="header-anchor" href="#os-getusername"><span>os.getusername()</span></a></h3><p>返回当前登录用户名。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>os<span class="token punctuation">.</span><span class="token function">getusername</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-isadmin" tabindex="-1"><a class="header-anchor" href="#os-isadmin"><span>os.isadmin()</span></a></h3><p>检查当前用户是否是管理员。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">if</span> os<span class="token punctuation">.</span><span class="token function">isadmin</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">then</span></span>
<span class="line">    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;User is admin&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">else</span></span>
<span class="line">    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;User is not admin&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="os-sha256-input" tabindex="-1"><a class="header-anchor" href="#os-sha256-input"><span>os.sha256(input)</span></a></h3><p>计算字符串的 SHA256 哈希值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> hash <span class="token operator">=</span> os<span class="token punctuation">.</span><span class="token function">sha256</span><span class="token punctuation">(</span><span class="token string">&quot;Hello World&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>hash<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="os-base64encrypt-input" tabindex="-1"><a class="header-anchor" href="#os-base64encrypt-input"><span>os.base64encrypt(input)</span></a></h3><p>将字符串编码为 Base64。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> encoded <span class="token operator">=</span> os<span class="token punctuation">.</span><span class="token function">base64encrypt</span><span class="token punctuation">(</span><span class="token string">&quot;Hello World&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>encoded<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="os-base64decrypt-input" tabindex="-1"><a class="header-anchor" href="#os-base64decrypt-input"><span>os.base64decrypt(input)</span></a></h3><p>将 Base64 字符串解码。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> decoded <span class="token operator">=</span> os<span class="token punctuation">.</span><span class="token function">base64decrypt</span><span class="token punctuation">(</span><span class="token string">&quot;SGVsbG8gV29ybGxcmVvcmxvYg==&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>decoded<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="os-timerstart" tabindex="-1"><a class="header-anchor" href="#os-timerstart"><span>os.timerstart()</span></a></h3><p>启动计时器，记录当前时间。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">timerstart</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-timerstop" tabindex="-1"><a class="header-anchor" href="#os-timerstop"><span>os.timerstop()</span></a></h3><p>停止计时器并返回从 timerstart 到 timerstop 之间的时间（秒）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">timerstart</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">for</span> i <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1000000</span> <span class="token keyword">do</span></span>
<span class="line">    <span class="token keyword">local</span> x <span class="token operator">=</span> i <span class="token operator">*</span> <span class="token number">2</span></span>
<span class="line"><span class="token keyword">end</span></span>
<span class="line"><span class="token keyword">local</span> elapsed <span class="token operator">=</span> os<span class="token punctuation">.</span><span class="token function">timerstop</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Elapsed time:&quot;</span><span class="token punctuation">,</span> elapsed<span class="token punctuation">,</span> <span class="token string">&quot;seconds&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>注意</strong>：</p><ul><li>如果在未调用 <code>timerstart</code> 的情况下调用 <code>timerstop</code>，将返回 <code>nil</code></li><li>每次调用 <code>timerstop</code> 后，计时器会被重置</li><li>返回的时间单位为秒（浮点数）</li></ul><h3 id="os-tui-drawbox-x-y-width-height-title-bordercolor-backgroundcolor" tabindex="-1"><a class="header-anchor" href="#os-tui-drawbox-x-y-width-height-title-bordercolor-backgroundcolor"><span>os.tui_drawbox(x, y, width, height, title, borderColor, backgroundColor)</span></a></h3><p>绘制带边框和标题的矩形框。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">tui_drawbox</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">&quot;Title&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;white&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;darkblue&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><p><strong>参数</strong>：</p><ul><li><code>x</code> - 矩形框的左上角 X 坐标</li><li><code>y</code> - 矩形框的左上角 Y 坐标</li><li><code>width</code> - 矩形框的宽度</li><li><code>height</code> - 矩形框的高度</li><li><code>title</code> - 矩形框的标题（可选）</li><li><code>borderColor</code> - 边框颜色（black, blue, cyan, darkblue, darkcyan, darkgray, darkgreen, darkmagenta, darkred, darkyellow, gray, green, magenta, red, white, yellow）</li><li><code>backgroundColor</code> - 背景颜色（同上）</li></ul><h3 id="os-tui-drawtext-x-y-text-foregroundcolor-backgroundcolor" tabindex="-1"><a class="header-anchor" href="#os-tui-drawtext-x-y-text-foregroundcolor-backgroundcolor"><span>os.tui_drawtext(x, y, text, foregroundColor, backgroundColor)</span></a></h3><p>在指定位置绘制文本。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">tui_drawtext</span><span class="token punctuation">(</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token string">&quot;Hello World!&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;yellow&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;black&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><p><strong>参数</strong>：</p><ul><li><code>x</code> - 文本的 X 坐标</li><li><code>y</code> - 文本的 Y 坐标</li><li><code>text</code> - 要绘制的文本内容</li><li><code>foregroundColor</code> - 前景色（同上）</li><li><code>backgroundColor</code> - 背景色（同上）</li></ul><h3 id="os-tui-setcolor-foregroundcolor-backgroundcolor" tabindex="-1"><a class="header-anchor" href="#os-tui-setcolor-foregroundcolor-backgroundcolor"><span>os.tui_setcolor(foregroundColor, backgroundColor)</span></a></h3><p>设置前景色和背景色。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">tui_setcolor</span><span class="token punctuation">(</span><span class="token string">&quot;white&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;black&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><p><strong>参数</strong>：</p><ul><li><code>foregroundColor</code> - 前景色（black, blue, cyan, darkblue, darkcyan, darkgray, darkgreen, darkmagenta, darkred, darkyellow, gray, green, magenta, red, white, yellow）</li><li><code>backgroundColor</code> - 背景色（同上）</li></ul><h3 id="os-tui-setcursor-x-y" tabindex="-1"><a class="header-anchor" href="#os-tui-setcursor-x-y"><span>os.tui_setcursor(x, y)</span></a></h3><p>设置光标位置。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">tui_setcursor</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><p><strong>参数</strong>：</p><ul><li><code>x</code> - 光标的 X 坐标</li><li><code>y</code> - 光标的 Y 坐标</li></ul><h3 id="os-tui-clear" tabindex="-1"><a class="header-anchor" href="#os-tui-clear"><span>os.tui_clear()</span></a></h3><p>清屏。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">tui_clear</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="os-tui-drawline-x-y-length-character-color" tabindex="-1"><a class="header-anchor" href="#os-tui-drawline-x-y-length-character-color"><span>os.tui_drawline(x, y, length, character, color)</span></a></h3><p>绘制水平线。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">tui_drawline</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token string">&quot;-&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;green&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><p><strong>参数</strong>：</p><ul><li><code>x</code> - 线的起始 X 坐标</li><li><code>y</code> - 线的起始 Y 坐标</li><li><code>length</code> - 线的长度</li><li><code>character</code> - 用于绘制线的字符</li><li><code>color</code> - 线的颜色（同上）</li></ul><hr><h2 id="输入输出库-io" tabindex="-1"><a class="header-anchor" href="#输入输出库-io"><span>输入输出库 (io)</span></a></h2><h3 id="io-close-file" tabindex="-1"><a class="header-anchor" href="#io-close-file"><span>io.close(file)</span></a></h3><p>关闭文件。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> file <span class="token operator">=</span> io<span class="token punctuation">.</span><span class="token function">open</span><span class="token punctuation">(</span><span class="token string">&quot;test.txt&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;w&quot;</span><span class="token punctuation">)</span></span>
<span class="line">file<span class="token punctuation">:</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token string">&quot;Hello&quot;</span><span class="token punctuation">)</span></span>
<span class="line">io<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span>file<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="io-flush" tabindex="-1"><a class="header-anchor" href="#io-flush"><span>io.flush()</span></a></h3><p>刷新所有打开文件的输出缓冲区。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">io<span class="token punctuation">.</span><span class="token function">flush</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="io-input-file" tabindex="-1"><a class="header-anchor" href="#io-input-file"><span>io.input([file])</span></a></h3><p>设置默认输入文件。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">io<span class="token punctuation">.</span><span class="token function">input</span><span class="token punctuation">(</span><span class="token string">&quot;input.txt&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="io-lines-filename" tabindex="-1"><a class="header-anchor" href="#io-lines-filename"><span>io.lines([filename])</span></a></h3><p>返回文件行的迭代器。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">for</span> line <span class="token keyword">in</span> io<span class="token punctuation">.</span><span class="token function">lines</span><span class="token punctuation">(</span><span class="token string">&quot;test.txt&quot;</span><span class="token punctuation">)</span> <span class="token keyword">do</span></span>
<span class="line">    <span class="token function">print</span><span class="token punctuation">(</span>line<span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="io-open-filename-mode" tabindex="-1"><a class="header-anchor" href="#io-open-filename-mode"><span>io.open(filename [, mode])</span></a></h3><p>打开文件，返回文件句柄。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> file <span class="token operator">=</span> io<span class="token punctuation">.</span><span class="token function">open</span><span class="token punctuation">(</span><span class="token string">&quot;test.txt&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;r&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">local</span> content <span class="token operator">=</span> file<span class="token punctuation">:</span><span class="token function">read</span><span class="token punctuation">(</span><span class="token string">&quot;*a&quot;</span><span class="token punctuation">)</span></span>
<span class="line">file<span class="token punctuation">:</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="io-output-file" tabindex="-1"><a class="header-anchor" href="#io-output-file"><span>io.output([file])</span></a></h3><p>设置默认输出文件。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">io<span class="token punctuation">.</span><span class="token function">output</span><span class="token punctuation">(</span><span class="token string">&quot;output.txt&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="io-popen-prog-mode" tabindex="-1"><a class="header-anchor" href="#io-popen-prog-mode"><span>io.popen(prog [, mode])</span></a></h3><p>启动程序并返回文件句柄。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> file <span class="token operator">=</span> io<span class="token punctuation">.</span><span class="token function">popen</span><span class="token punctuation">(</span><span class="token string">&quot;ls&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;r&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">local</span> output <span class="token operator">=</span> file<span class="token punctuation">:</span><span class="token function">read</span><span class="token punctuation">(</span><span class="token string">&quot;*a&quot;</span><span class="token punctuation">)</span></span>
<span class="line">file<span class="token punctuation">:</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="io-read" tabindex="-1"><a class="header-anchor" href="#io-read"><span>io.read(...)</span></a></h3><p>从默认输入文件读取数据。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> input <span class="token operator">=</span> io<span class="token punctuation">.</span><span class="token function">read</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>input<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="io-tmpfile" tabindex="-1"><a class="header-anchor" href="#io-tmpfile"><span>io.tmpfile()</span></a></h3><p>返回临时文件的句柄。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> file <span class="token operator">=</span> io<span class="token punctuation">.</span><span class="token function">tmpfile</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">file<span class="token punctuation">:</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token string">&quot;temp data&quot;</span><span class="token punctuation">)</span></span>
<span class="line">file<span class="token punctuation">:</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="io-type-file" tabindex="-1"><a class="header-anchor" href="#io-type-file"><span>io.type(file)</span></a></h3><p>检查文件是否是打开的文件句柄。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> file <span class="token operator">=</span> io<span class="token punctuation">.</span><span class="token function">open</span><span class="token punctuation">(</span><span class="token string">&quot;test.txt&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;r&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>io<span class="token punctuation">.</span><span class="token function">type</span><span class="token punctuation">(</span>file<span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- file</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="io-write" tabindex="-1"><a class="header-anchor" href="#io-write"><span>io.write(...)</span></a></h3><p>写入数据到默认输出文件。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">io<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token string">&quot;Hello, World!\\n&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><hr><h2 id="协程库-coroutine" tabindex="-1"><a class="header-anchor" href="#协程库-coroutine"><span>协程库 (coroutine)</span></a></h2><h3 id="coroutine-create-f" tabindex="-1"><a class="header-anchor" href="#coroutine-create-f"><span>coroutine.create(f)</span></a></h3><p>创建新的协程。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">co <span class="token operator">=</span> coroutine<span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Coroutine started&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="coroutine-resume-co-val1" tabindex="-1"><a class="header-anchor" href="#coroutine-resume-co-val1"><span>coroutine.resume(co [, val1, ...])</span></a></h3><p>继续或启动协程。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">coroutine<span class="token punctuation">.</span><span class="token function">resume</span><span class="token punctuation">(</span>co<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="coroutine-running" tabindex="-1"><a class="header-anchor" href="#coroutine-running"><span>coroutine.running()</span></a></h3><p>返回当前运行的协程。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>coroutine<span class="token punctuation">.</span><span class="token function">running</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="coroutine-status-co" tabindex="-1"><a class="header-anchor" href="#coroutine-status-co"><span>coroutine.status(co)</span></a></h3><p>返回协程的状态。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>coroutine<span class="token punctuation">.</span><span class="token function">status</span><span class="token punctuation">(</span>co<span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- running, suspended, normal, dead</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="coroutine-wrap-f" tabindex="-1"><a class="header-anchor" href="#coroutine-wrap-f"><span>coroutine.wrap(f)</span></a></h3><p>创建包装函数的函数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">co <span class="token operator">=</span> coroutine<span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Coroutine&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">end</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">local</span> wrapped <span class="token operator">=</span> coroutine<span class="token punctuation">.</span><span class="token function">wrap</span><span class="token punctuation">(</span>co<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">wrapped</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="coroutine-yield" tabindex="-1"><a class="header-anchor" href="#coroutine-yield"><span>coroutine.yield(...)</span></a></h3><p>挂起当前协程。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">coroutine<span class="token punctuation">.</span><span class="token function">yield</span><span class="token punctuation">(</span><span class="token string">&quot;value&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><hr><h2 id="表库-table" tabindex="-1"><a class="header-anchor" href="#表库-table"><span>表库 (table)</span></a></h2><h3 id="table-concat-list-sep-i-j" tabindex="-1"><a class="header-anchor" href="#table-concat-list-sep-i-j"><span>table.concat(list [, sep [, i [, j]])</span></a></h3><p>连接表中的元素。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token string">&quot;a&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;b&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;c&quot;</span><span class="token punctuation">}</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>table<span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span>t<span class="token punctuation">,</span> <span class="token string">&quot;, &quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- a, b, c</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="table-insert-list-pos-value" tabindex="-1"><a class="header-anchor" href="#table-insert-list-pos-value"><span>table.insert(list, [pos,] value)</span></a></h3><p>在表中插入元素。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">}</span></span>
<span class="line">table<span class="token punctuation">.</span><span class="token function">insert</span><span class="token punctuation">(</span>t<span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="table-maxn-t" tabindex="-1"><a class="header-anchor" href="#table-maxn-t"><span>table.maxn(t)</span></a></h3><p>返回表的最大数字索引（已弃用，使用 # 运算符）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token keyword">nil</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">}</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>table<span class="token punctuation">.</span><span class="token function">maxn</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 4</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="table-remove-list-pos" tabindex="-1"><a class="header-anchor" href="#table-remove-list-pos"><span>table.remove(list [, pos])</span></a></h3><p>从表中删除元素。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">}</span></span>
<span class="line">table<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span>t<span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="table-sort-list-comp" tabindex="-1"><a class="header-anchor" href="#table-sort-list-comp"><span>table.sort(list [, comp])</span></a></h3><p>对表进行排序。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">}</span></span>
<span class="line">table<span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><hr><h2 id="调试库-debug" tabindex="-1"><a class="header-anchor" href="#调试库-debug"><span>调试库 (debug)</span></a></h2><h3 id="debug-debug" tabindex="-1"><a class="header-anchor" href="#debug-debug"><span>debug.debug()</span></a></h3><p>进入调试模式。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">debug<span class="token punctuation">.</span><span class="token function">debug</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-getfenv-object" tabindex="-1"><a class="header-anchor" href="#debug-getfenv-object"><span>debug.getfenv(object)</span></a></h3><p>返回对象的环境。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>debug<span class="token punctuation">.</span><span class="token function">getfenv</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">return</span> x <span class="token keyword">end</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-gethook" tabindex="-1"><a class="header-anchor" href="#debug-gethook"><span>debug.gethook()</span></a></h3><p>返回当前的钩子函数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>debug<span class="token punctuation">.</span><span class="token function">gethook</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-getinfo-thread-f-what" tabindex="-1"><a class="header-anchor" href="#debug-getinfo-thread-f-what"><span>debug.getinfo([thread [, f [, what]])</span></a></h3><p>返回函数的信息。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>debug<span class="token punctuation">.</span><span class="token function">getinfo</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-getlocal-thread-f-loc" tabindex="-1"><a class="header-anchor" href="#debug-getlocal-thread-f-loc"><span>debug.getlocal([thread [, f [, loc]])</span></a></h3><p>返回函数的局部变量。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>debug<span class="token punctuation">.</span><span class="token function">getlocal</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-getmetatable-object" tabindex="-1"><a class="header-anchor" href="#debug-getmetatable-object"><span>debug.getmetatable(object)</span></a></h3><p>返回对象的元表。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">t <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span></span>
<span class="line">mt <span class="token operator">=</span> <span class="token punctuation">{</span>__add <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span> <span class="token keyword">return</span> a <span class="token operator">+</span> b <span class="token keyword">end</span><span class="token punctuation">}</span></span>
<span class="line"><span class="token function">setmetatable</span><span class="token punctuation">(</span>t<span class="token punctuation">,</span> mt<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>debug<span class="token punctuation">.</span><span class="token function">getmetatable</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span><span class="token punctuation">.</span>__add<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="debug-getregistry" tabindex="-1"><a class="header-anchor" href="#debug-getregistry"><span>debug.getregistry()</span></a></h3><p>返回注册表。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>debug<span class="token punctuation">.</span><span class="token function">getregistry</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-getupvalue-f-i" tabindex="-1"><a class="header-anchor" href="#debug-getupvalue-f-i"><span>debug.getupvalue(f [, i])</span></a></h3><p>返回函数的上值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>debug<span class="token punctuation">.</span><span class="token function">getupvalue</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-setfenv-object-table" tabindex="-1"><a class="header-anchor" href="#debug-setfenv-object-table"><span>debug.setfenv(object, table)</span></a></h3><p>设置对象的环境。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">debug<span class="token punctuation">.</span><span class="token function">setfenv</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">return</span> x <span class="token keyword">end</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-sethook-hook-mask-count" tabindex="-1"><a class="header-anchor" href="#debug-sethook-hook-mask-count"><span>debug.sethook(hook, mask [, count])</span></a></h3><p>设置钩子函数。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">debug<span class="token punctuation">.</span><span class="token function">sethook</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Hook called&quot;</span><span class="token punctuation">)</span> <span class="token keyword">end</span><span class="token punctuation">,</span> <span class="token string">&quot;c&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-setlocal-thread-f-level-value" tabindex="-1"><a class="header-anchor" href="#debug-setlocal-thread-f-level-value"><span>debug.setlocal([thread [, f,] level, value)</span></a></h3><p>设置函数的局部变量。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">debug<span class="token punctuation">.</span><span class="token function">setlocal</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">&quot;value&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-setmetatable-object-table" tabindex="-1"><a class="header-anchor" href="#debug-setmetatable-object-table"><span>debug.setmetatable(object, table)</span></a></h3><p>设置对象的元表。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">debug<span class="token punctuation">.</span><span class="token function">setmetatable</span><span class="token punctuation">(</span>t<span class="token punctuation">,</span> mt<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-setupvalue-f-i-value" tabindex="-1"><a class="header-anchor" href="#debug-setupvalue-f-i-value"><span>debug.setupvalue(f [, i,] value)</span></a></h3><p>设置函数的上值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">debug<span class="token punctuation">.</span><span class="token function">setupvalue</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">&quot;newvalue&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="debug-traceback-thread-message-level" tabindex="-1"><a class="header-anchor" href="#debug-traceback-thread-message-level"><span>debug.traceback([thread [, message [, level]])</span></a></h3><p>返回调用栈的跟踪信息。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>debug<span class="token punctuation">.</span><span class="token function">traceback</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><hr><h2 id="位运算库-bit" tabindex="-1"><a class="header-anchor" href="#位运算库-bit"><span>位运算库 (bit)</span></a></h2><h3 id="bit-band-x1-x2" tabindex="-1"><a class="header-anchor" href="#bit-band-x1-x2"><span>bit.band(x1, x2 [, ...])</span></a></h3><p>按位与操作。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>bit<span class="token punctuation">.</span><span class="token function">band</span><span class="token punctuation">(</span><span class="token number">0x0F</span><span class="token punctuation">,</span> <span class="token number">0x0F</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0x0F</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="bit-bnot-x" tabindex="-1"><a class="header-anchor" href="#bit-bnot-x"><span>bit.bnot(x)</span></a></h3><p>按位非操作。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>bit<span class="token punctuation">.</span><span class="token function">bnot</span><span class="token punctuation">(</span><span class="token number">0x0F</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0xFFFFFFF0</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="bit-bor-x1-x2" tabindex="-1"><a class="header-anchor" href="#bit-bor-x1-x2"><span>bit.bor(x1, x2 [, ...])</span></a></h3><p>按位或操作。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>bit<span class="token punctuation">.</span><span class="token function">bor</span><span class="token punctuation">(</span><span class="token number">0x0F</span><span class="token punctuation">,</span> <span class="token number">0x0F</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0x0F</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="bit-bxor-x1-x2" tabindex="-1"><a class="header-anchor" href="#bit-bxor-x1-x2"><span>bit.bxor(x1, x2 [, ...])</span></a></h3><p>按位异或操作。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>bit<span class="token punctuation">.</span><span class="token function">bxor</span><span class="token punctuation">(</span><span class="token number">0x0F</span><span class="token punctuation">,</span> <span class="token number">0x0F</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0x00</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="bit-lshift-x-disp" tabindex="-1"><a class="header-anchor" href="#bit-lshift-x-disp"><span>bit.lshift(x, disp)</span></a></h3><p>按位左移。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>bit<span class="token punctuation">.</span><span class="token function">lshift</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 4</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="bit-rshift-x-disp" tabindex="-1"><a class="header-anchor" href="#bit-rshift-x-disp"><span>bit.rshift(x, disp)</span></a></h3><p>按位右移。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>bit<span class="token punctuation">.</span><span class="token function">rshift</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 1</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="bit-arshift-x-disp" tabindex="-1"><a class="header-anchor" href="#bit-arshift-x-disp"><span>bit.arshift(x, disp)</span></a></h3><p>按位算术右移。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>bit<span class="token punctuation">.</span><span class="token function">arshift</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 1</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="bit-rol-x-disp" tabindex="-1"><a class="header-anchor" href="#bit-rol-x-disp"><span>bit.rol(x, disp)</span></a></h3><p>循环左移。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>bit<span class="token punctuation">.</span><span class="token function">rol</span><span class="token punctuation">(</span><span class="token number">0x0F</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0xF0</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="bit-ror-x-disp" tabindex="-1"><a class="header-anchor" href="#bit-ror-x-disp"><span>bit.ror(x, disp)</span></a></h3><p>循环右移。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>bit<span class="token punctuation">.</span><span class="token function">ror</span><span class="token punctuation">(</span><span class="token number">0x0F</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 0x0F</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="bit-tobit-x" tabindex="-1"><a class="header-anchor" href="#bit-tobit-x"><span>bit.tobit(x)</span></a></h3><p>转换为位字符串。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>bit<span class="token punctuation">.</span><span class="token function">tobit</span><span class="token punctuation">(</span><span class="token number">0x0F</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">-- 00001111</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><hr><h2 id="编码库-enc" tabindex="-1"><a class="header-anchor" href="#编码库-enc"><span>编码库 (enc)</span></a></h2><h3 id="enc-base64encode-input" tabindex="-1"><a class="header-anchor" href="#enc-base64encode-input"><span>enc.base64encode(input)</span></a></h3><p>将字符串编码为 Base64。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> encoded <span class="token operator">=</span> enc<span class="token punctuation">.</span><span class="token function">base64encode</span><span class="token punctuation">(</span><span class="token string">&quot;Hello World&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>encoded<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="enc-base64decode-input" tabindex="-1"><a class="header-anchor" href="#enc-base64decode-input"><span>enc.base64decode(input)</span></a></h3><p>将 Base64 字符串解码。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> decoded <span class="token operator">=</span> enc<span class="token punctuation">.</span><span class="token function">base64decode</span><span class="token punctuation">(</span><span class="token string">&quot;SGVsbG8gV29ybGxcmVvcmxvYg==&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>decoded<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><hr><h2 id="json-库" tabindex="-1"><a class="header-anchor" href="#json-库"><span>JSON 库</span></a></h2><h3 id="json-encode-table" tabindex="-1"><a class="header-anchor" href="#json-encode-table"><span>json.encode(table)</span></a></h3><p>将 Lua 表编码为 JSON 字符串。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> data <span class="token operator">=</span> <span class="token punctuation">{</span>name <span class="token operator">=</span> <span class="token string">&quot;John&quot;</span><span class="token punctuation">,</span> age <span class="token operator">=</span> <span class="token number">30</span><span class="token punctuation">}</span></span>
<span class="line"><span class="token keyword">local</span> jsonStr <span class="token operator">=</span> json<span class="token punctuation">.</span><span class="token function">encode</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>jsonStr<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="json-decode-string" tabindex="-1"><a class="header-anchor" href="#json-decode-string"><span>json.decode(string)</span></a></h3><p>将 JSON 字符串解码为 Lua 表。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> jsonStr <span class="token operator">=</span> <span class="token string">&#39;{&quot;name&quot;: &quot;John&quot;, &quot;age&quot;: 30}&#39;</span></span>
<span class="line"><span class="token keyword">local</span> data <span class="token operator">=</span> json<span class="token punctuation">.</span><span class="token function">decode</span><span class="token punctuation">(</span>jsonStr<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>data<span class="token punctuation">.</span>name<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>data<span class="token punctuation">.</span>age<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="json-null" tabindex="-1"><a class="header-anchor" href="#json-null"><span>json.null()</span></a></h3><p>返回 null 值。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> nullValue <span class="token operator">=</span> json<span class="token punctuation">.</span><span class="token function">null</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>nullValue<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="json-parse-string" tabindex="-1"><a class="header-anchor" href="#json-parse-string"><span>json.parse(string)</span></a></h3><p>解析 JSON 字符串（同 decode）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> jsonStr <span class="token operator">=</span> <span class="token string">&#39;{&quot;name&quot;: &quot;John&quot;, &quot;age&quot;: 30}&#39;</span></span>
<span class="line"><span class="token keyword">local</span> data <span class="token operator">=</span> json<span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span>jsonStr<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>data<span class="token punctuation">.</span>name<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="json-stringify-table" tabindex="-1"><a class="header-anchor" href="#json-stringify-table"><span>json.stringify(table)</span></a></h3><p>将 Lua 表转换为 JSON 字符串（同 encode）。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> data <span class="token operator">=</span> <span class="token punctuation">{</span>name <span class="token operator">=</span> <span class="token string">&quot;John&quot;</span><span class="token punctuation">,</span> age <span class="token operator">=</span> <span class="token number">30</span><span class="token punctuation">}</span></span>
<span class="line"><span class="token keyword">local</span> jsonStr <span class="token operator">=</span> json<span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>jsonStr<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><hr><h2 id="包库-package" tabindex="-1"><a class="header-anchor" href="#包库-package"><span>包库 (package)</span></a></h2><h3 id="package-loaded" tabindex="-1"><a class="header-anchor" href="#package-loaded"><span>package.loaded</span></a></h3><p>已加载的包表。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>package<span class="token punctuation">.</span>loaded<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="package-loaders" tabindex="-1"><a class="header-anchor" href="#package-loaders"><span>package.loaders</span></a></h3><p>包加载器表。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>package<span class="token punctuation">.</span>loaders<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="package-loadlib-libname-initfunc" tabindex="-1"><a class="header-anchor" href="#package-loadlib-libname-initfunc"><span>package.loadlib(libname [, initfunc])</span></a></h3><p>加载 C 库。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">package<span class="token punctuation">.</span><span class="token function">loadlib</span><span class="token punctuation">(</span><span class="token string">&quot;mylib&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="package-path" tabindex="-1"><a class="header-anchor" href="#package-path"><span>package.path</span></a></h3><p>包搜索路径。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>package<span class="token punctuation">.</span>path<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="package-searchpath-name-path-sep-rep" tabindex="-1"><a class="header-anchor" href="#package-searchpath-name-path-sep-rep"><span>package.searchpath(name [, path [, sep [, rep]])</span></a></h3><p>搜索包路径。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>package<span class="token punctuation">.</span><span class="token function">searchpath</span><span class="token punctuation">(</span><span class="token string">&quot;mylib&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="package-seeall-name" tabindex="-1"><a class="header-anchor" href="#package-seeall-name"><span>package.seeall([name])</span></a></h3><p>列出所有已加载的包。</p><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span>package<span class="token punctuation">.</span><span class="token function">seeall</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><hr><h2 id="使用示例" tabindex="-1"><a class="header-anchor" href="#使用示例"><span>使用示例</span></a></h2><h3 id="交互式-lua-shell" tabindex="-1"><a class="header-anchor" href="#交互式-lua-shell"><span>交互式 Lua Shell</span></a></h3><p>使用 <code>lua --shell</code> 进入交互模式：</p><div class="language-text line-numbers-mode" data-highlighter="prismjs" data-ext="text"><pre><code><span class="line">lua --shell</span>
<span class="line">====================================</span>
<span class="line">        Lua Interactive Shell</span>
<span class="line">====================================</span>
<span class="line">Type &#39;exit&#39; or &#39;quit&#39; to exit</span>
<span class="line"></span>
<span class="line">lua&gt; print(&quot;Hello, World!&quot;)</span>
<span class="line">Hello, World!</span>
<span class="line"></span>
<span class="line">lua&gt; os.gethostname()</span>
<span class="line">myserver</span>
<span class="line"></span>
<span class="line">lua&gt; os.sha256(&quot;Hello&quot;)</span>
<span class="line">a591a6d40bf420404a011733cfb7b1d12e</span>
<span class="line"></span>
<span class="line">lua&gt; exit</span>
<span class="line">Exiting Lua shell...</span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="执行-lua-脚本文件" tabindex="-1"><a class="header-anchor" href="#执行-lua-脚本文件"><span>执行 Lua 脚本文件</span></a></h3><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">lua script<span class="token punctuation">.</span>lua</span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div></div></div><h3 id="系统信息查询" tabindex="-1"><a class="header-anchor" href="#系统信息查询"><span>系统信息查询</span></a></h3><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Hostname:&quot;</span><span class="token punctuation">,</span> os<span class="token punctuation">.</span><span class="token function">gethostname</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Username:&quot;</span><span class="token punctuation">,</span> os<span class="token punctuation">.</span><span class="token function">getusername</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Is Admin:&quot;</span><span class="token punctuation">,</span> os<span class="token punctuation">.</span><span class="token function">isadmin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;SHA256:&quot;</span><span class="token punctuation">,</span> os<span class="token punctuation">.</span><span class="token function">sha256</span><span class="token punctuation">(</span><span class="token string">&quot;Hello&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="环境变量操作" tabindex="-1"><a class="header-anchor" href="#环境变量操作"><span>环境变量操作</span></a></h3><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line">os<span class="token punctuation">.</span><span class="token function">setenv</span><span class="token punctuation">(</span><span class="token string">&quot;MYVAR&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;value&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span>os<span class="token punctuation">.</span><span class="token function">getenv</span><span class="token punctuation">(</span><span class="token string">&quot;MYVAR&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line">os<span class="token punctuation">.</span><span class="token function">delenv</span><span class="token punctuation">(</span><span class="token string">&quot;MYVAR&quot;</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="加密和编码" tabindex="-1"><a class="header-anchor" href="#加密和编码"><span>加密和编码</span></a></h3><div class="language-lua line-numbers-mode" data-highlighter="prismjs" data-ext="lua"><pre><code><span class="line"><span class="token keyword">local</span> hash <span class="token operator">=</span> os<span class="token punctuation">.</span><span class="token function">sha256</span><span class="token punctuation">(</span><span class="token string">&quot;password&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">local</span> encoded <span class="token operator">=</span> os<span class="token punctuation">.</span><span class="token function">base64encrypt</span><span class="token punctuation">(</span><span class="token string">&quot;secret&quot;</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">local</span> decoded <span class="token operator">=</span> os<span class="token punctuation">.</span><span class="token function">base64decrypt</span><span class="token punctuation">(</span>encoded<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Hash:&quot;</span><span class="token punctuation">,</span> hash<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Encoded:&quot;</span><span class="token punctuation">,</span> encoded<span class="token punctuation">)</span></span>
<span class="line"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;Decoded:&quot;</span><span class="token punctuation">,</span> decoded<span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="注意事项" tabindex="-1"><a class="header-anchor" href="#注意事项"><span>注意事项</span></a></h2><ol><li><strong>交互模式</strong>：使用 <code>lua --shell</code> 进入交互式 Lua Shell</li><li><strong>错误处理</strong>：所有 Lua 执行错误都会被捕获并显示</li><li><strong>系统函数</strong>：<code>os</code> 库包含 CMLeonOS 特定的系统函数</li><li><strong>加密支持</strong>：支持 SHA256 和 Base64 编码/解码</li><li><strong>标准 Lua</strong>：完全兼容 Lua 5.1 标准</li></ol><h2 id="版本信息" tabindex="-1"><a class="header-anchor" href="#版本信息"><span>版本信息</span></a></h2><ul><li><strong>Lua 版本</strong>：5.2</li><li><strong>CMLeonOS 版本</strong>：最新</li></ul>`,514)])])}const c=s(p,[["render",l]]),u=JSON.parse('{"path":"/lua.html","title":"CMLeonOS Lua API 文档","lang":"zh-CN","frontmatter":{},"headers":[{"level":2,"title":"基础库 (base)","slug":"基础库-base","link":"#基础库-base","children":[{"level":3,"title":"assert(v [, message])","slug":"assert-v-message","link":"#assert-v-message","children":[]},{"level":3,"title":"collectgarbage([opt])","slug":"collectgarbage-opt","link":"#collectgarbage-opt","children":[]},{"level":3,"title":"dofile([filename])","slug":"dofile-filename","link":"#dofile-filename","children":[]},{"level":3,"title":"input([prompt])","slug":"input-prompt","link":"#input-prompt","children":[]},{"level":3,"title":"error(message [, level])","slug":"error-message-level","link":"#error-message-level","children":[]},{"level":3,"title":"ipairs(t)","slug":"ipairs-t","link":"#ipairs-t","children":[]},{"level":3,"title":"loadfile([filename])","slug":"loadfile-filename","link":"#loadfile-filename","children":[]},{"level":3,"title":"load(string [, chunkname])","slug":"load-string-chunkname","link":"#load-string-chunkname","children":[]},{"level":3,"title":"loadstring(string [, chunkname])","slug":"loadstring-string-chunkname","link":"#loadstring-string-chunkname","children":[]},{"level":3,"title":"next(table [, index])","slug":"next-table-index","link":"#next-table-index","children":[]},{"level":3,"title":"pairs(t)","slug":"pairs-t","link":"#pairs-t","children":[]},{"level":3,"title":"pcall(f [, arg1, ...])","slug":"pcall-f-arg1","link":"#pcall-f-arg1","children":[]},{"level":3,"title":"print(...)","slug":"print","link":"#print","children":[]},{"level":3,"title":"rawequal(v1, v2)","slug":"rawequal-v1-v2","link":"#rawequal-v1-v2","children":[]},{"level":3,"title":"rawlen(v)","slug":"rawlen-v","link":"#rawlen-v","children":[]},{"level":3,"title":"rawget(table, index)","slug":"rawget-table-index","link":"#rawget-table-index","children":[]},{"level":3,"title":"rawset(table, index, value)","slug":"rawset-table-index-value","link":"#rawset-table-index-value","children":[]},{"level":3,"title":"select(index, ...)","slug":"select-index","link":"#select-index","children":[]},{"level":3,"title":"getmetatable(object)","slug":"getmetatable-object","link":"#getmetatable-object","children":[]},{"level":3,"title":"setmetatable(table, metatable)","slug":"setmetatable-table-metatable","link":"#setmetatable-table-metatable","children":[]},{"level":3,"title":"tonumber(e [, base])","slug":"tonumber-e-base","link":"#tonumber-e-base","children":[]},{"level":3,"title":"tostring(v)","slug":"tostring-v","link":"#tostring-v","children":[]},{"level":3,"title":"type(v)","slug":"type-v","link":"#type-v","children":[]},{"level":3,"title":"xpcall(f [, arg1, ...])","slug":"xpcall-f-arg1","link":"#xpcall-f-arg1","children":[]}]},{"level":2,"title":"数学库 (math)","slug":"数学库-math","link":"#数学库-math","children":[{"level":3,"title":"math.abs(x)","slug":"math-abs-x","link":"#math-abs-x","children":[]},{"level":3,"title":"math.acos(x)","slug":"math-acos-x","link":"#math-acos-x","children":[]},{"level":3,"title":"math.asin(x)","slug":"math-asin-x","link":"#math-asin-x","children":[]},{"level":3,"title":"math.atan2(y, x)","slug":"math-atan2-y-x","link":"#math-atan2-y-x","children":[]},{"level":3,"title":"math.atan(x)","slug":"math-atan-x","link":"#math-atan-x","children":[]},{"level":3,"title":"math.ceil(x)","slug":"math-ceil-x","link":"#math-ceil-x","children":[]},{"level":3,"title":"math.cosh(x)","slug":"math-cosh-x","link":"#math-cosh-x","children":[]},{"level":3,"title":"math.cos(x)","slug":"math-cos-x","link":"#math-cos-x","children":[]},{"level":3,"title":"math.deg(x)","slug":"math-deg-x","link":"#math-deg-x","children":[]},{"level":3,"title":"math.exp(x)","slug":"math-exp-x","link":"#math-exp-x","children":[]},{"level":3,"title":"math.floor(x)","slug":"math-floor-x","link":"#math-floor-x","children":[]},{"level":3,"title":"math.fmod(x, y)","slug":"math-fmod-x-y","link":"#math-fmod-x-y","children":[]},{"level":3,"title":"math.frexp(x)","slug":"math-frexp-x","link":"#math-frexp-x","children":[]},{"level":3,"title":"math.ldexp(m, e)","slug":"math-ldexp-m-e","link":"#math-ldexp-m-e","children":[]},{"level":3,"title":"math.log10(x)","slug":"math-log10-x","link":"#math-log10-x","children":[]},{"level":3,"title":"math.log(x [, base])","slug":"math-log-x-base","link":"#math-log-x-base","children":[]},{"level":3,"title":"math.max(x1, ...)","slug":"math-max-x1","link":"#math-max-x1","children":[]},{"level":3,"title":"math.min(x1, ...)","slug":"math-min-x1","link":"#math-min-x1","children":[]},{"level":3,"title":"math.modf(x)","slug":"math-modf-x","link":"#math-modf-x","children":[]},{"level":3,"title":"math.pow(x, y)","slug":"math-pow-x-y","link":"#math-pow-x-y","children":[]},{"level":3,"title":"math.rad(x)","slug":"math-rad-x","link":"#math-rad-x","children":[]},{"level":3,"title":"math.random([m [, n]])","slug":"math-random-m-n","link":"#math-random-m-n","children":[]},{"level":3,"title":"math.randomseed(x)","slug":"math-randomseed-x","link":"#math-randomseed-x","children":[]},{"level":3,"title":"math.sinh(x)","slug":"math-sinh-x","link":"#math-sinh-x","children":[]},{"level":3,"title":"math.sin(x)","slug":"math-sin-x","link":"#math-sin-x","children":[]},{"level":3,"title":"math.sqrt(x)","slug":"math-sqrt-x","link":"#math-sqrt-x","children":[]},{"level":3,"title":"math.tanh(x)","slug":"math-tanh-x","link":"#math-tanh-x","children":[]},{"level":3,"title":"math.tan(x)","slug":"math-tan-x","link":"#math-tan-x","children":[]},{"level":3,"title":"math.pi","slug":"math-pi","link":"#math-pi","children":[]},{"level":3,"title":"math.huge","slug":"math-huge","link":"#math-huge","children":[]}]},{"level":2,"title":"字符串库 (string)","slug":"字符串库-string","link":"#字符串库-string","children":[{"level":3,"title":"string.byte(s [, i [, j]])","slug":"string-byte-s-i-j","link":"#string-byte-s-i-j","children":[]},{"level":3,"title":"string.char(...)","slug":"string-char","link":"#string-char","children":[]},{"level":3,"title":"string.dump(function)","slug":"string-dump-function","link":"#string-dump-function","children":[]},{"level":3,"title":"string.find(s, pattern [, init [, plain]])","slug":"string-find-s-pattern-init-plain","link":"#string-find-s-pattern-init-plain","children":[]},{"level":3,"title":"string.format(formatstring, ...)","slug":"string-format-formatstring","link":"#string-format-formatstring","children":[]},{"level":3,"title":"string.gmatch(s, pattern)","slug":"string-gmatch-s-pattern","link":"#string-gmatch-s-pattern","children":[]},{"level":3,"title":"string.gsub(s, pattern, repl [, n])","slug":"string-gsub-s-pattern-repl-n","link":"#string-gsub-s-pattern-repl-n","children":[]},{"level":3,"title":"string.len(s)","slug":"string-len-s","link":"#string-len-s","children":[]},{"level":3,"title":"string.lower(s)","slug":"string-lower-s","link":"#string-lower-s","children":[]},{"level":3,"title":"string.match(s, pattern [, init])","slug":"string-match-s-pattern-init","link":"#string-match-s-pattern-init","children":[]},{"level":3,"title":"string.rep(s, n)","slug":"string-rep-s-n","link":"#string-rep-s-n","children":[]},{"level":3,"title":"string.reverse(s)","slug":"string-reverse-s","link":"#string-reverse-s","children":[]},{"level":3,"title":"string.sub(s, i [, j])","slug":"string-sub-s-i-j","link":"#string-sub-s-i-j","children":[]},{"level":3,"title":"string.upper(s)","slug":"string-upper-s","link":"#string-upper-s","children":[]}]},{"level":2,"title":"操作系统库 (os)","slug":"操作系统库-os","link":"#操作系统库-os","children":[{"level":3,"title":"os.clock()","slug":"os-clock","link":"#os-clock","children":[]},{"level":3,"title":"os.gethostname()","slug":"os-gethostname","link":"#os-gethostname","children":[]},{"level":3,"title":"os.getenv(varname)","slug":"os-getenv-varname","link":"#os-getenv-varname","children":[]},{"level":3,"title":"os.setenv(varname, value)","slug":"os-setenv-varname-value","link":"#os-setenv-varname-value","children":[]},{"level":3,"title":"os.delenv(varname)","slug":"os-delenv-varname","link":"#os-delenv-varname","children":[]},{"level":3,"title":"os.addenv(varname, value)","slug":"os-addenv-varname-value","link":"#os-addenv-varname-value","children":[]},{"level":3,"title":"os.execute(command)","slug":"os-execute-command","link":"#os-execute-command","children":[]},{"level":3,"title":"os.executefile(path)","slug":"os-executefile-path","link":"#os-executefile-path","children":[]},{"level":3,"title":"os.reboot()","slug":"os-reboot","link":"#os-reboot","children":[]},{"level":3,"title":"os.shutdown()","slug":"os-shutdown","link":"#os-shutdown","children":[]},{"level":3,"title":"os.sleep(seconds)","slug":"os-sleep-seconds","link":"#os-sleep-seconds","children":[]},{"level":3,"title":"os.beep()","slug":"os-beep","link":"#os-beep","children":[]},{"level":3,"title":"os.clear()","slug":"os-clear","link":"#os-clear","children":[]},{"level":3,"title":"os.getusername()","slug":"os-getusername","link":"#os-getusername","children":[]},{"level":3,"title":"os.isadmin()","slug":"os-isadmin","link":"#os-isadmin","children":[]},{"level":3,"title":"os.sha256(input)","slug":"os-sha256-input","link":"#os-sha256-input","children":[]},{"level":3,"title":"os.base64encrypt(input)","slug":"os-base64encrypt-input","link":"#os-base64encrypt-input","children":[]},{"level":3,"title":"os.base64decrypt(input)","slug":"os-base64decrypt-input","link":"#os-base64decrypt-input","children":[]},{"level":3,"title":"os.timerstart()","slug":"os-timerstart","link":"#os-timerstart","children":[]},{"level":3,"title":"os.timerstop()","slug":"os-timerstop","link":"#os-timerstop","children":[]},{"level":3,"title":"os.tui_drawbox(x, y, width, height, title, borderColor, backgroundColor)","slug":"os-tui-drawbox-x-y-width-height-title-bordercolor-backgroundcolor","link":"#os-tui-drawbox-x-y-width-height-title-bordercolor-backgroundcolor","children":[]},{"level":3,"title":"os.tui_drawtext(x, y, text, foregroundColor, backgroundColor)","slug":"os-tui-drawtext-x-y-text-foregroundcolor-backgroundcolor","link":"#os-tui-drawtext-x-y-text-foregroundcolor-backgroundcolor","children":[]},{"level":3,"title":"os.tui_setcolor(foregroundColor, backgroundColor)","slug":"os-tui-setcolor-foregroundcolor-backgroundcolor","link":"#os-tui-setcolor-foregroundcolor-backgroundcolor","children":[]},{"level":3,"title":"os.tui_setcursor(x, y)","slug":"os-tui-setcursor-x-y","link":"#os-tui-setcursor-x-y","children":[]},{"level":3,"title":"os.tui_clear()","slug":"os-tui-clear","link":"#os-tui-clear","children":[]},{"level":3,"title":"os.tui_drawline(x, y, length, character, color)","slug":"os-tui-drawline-x-y-length-character-color","link":"#os-tui-drawline-x-y-length-character-color","children":[]}]},{"level":2,"title":"输入输出库 (io)","slug":"输入输出库-io","link":"#输入输出库-io","children":[{"level":3,"title":"io.close(file)","slug":"io-close-file","link":"#io-close-file","children":[]},{"level":3,"title":"io.flush()","slug":"io-flush","link":"#io-flush","children":[]},{"level":3,"title":"io.input([file])","slug":"io-input-file","link":"#io-input-file","children":[]},{"level":3,"title":"io.lines([filename])","slug":"io-lines-filename","link":"#io-lines-filename","children":[]},{"level":3,"title":"io.open(filename [, mode])","slug":"io-open-filename-mode","link":"#io-open-filename-mode","children":[]},{"level":3,"title":"io.output([file])","slug":"io-output-file","link":"#io-output-file","children":[]},{"level":3,"title":"io.popen(prog [, mode])","slug":"io-popen-prog-mode","link":"#io-popen-prog-mode","children":[]},{"level":3,"title":"io.read(...)","slug":"io-read","link":"#io-read","children":[]},{"level":3,"title":"io.tmpfile()","slug":"io-tmpfile","link":"#io-tmpfile","children":[]},{"level":3,"title":"io.type(file)","slug":"io-type-file","link":"#io-type-file","children":[]},{"level":3,"title":"io.write(...)","slug":"io-write","link":"#io-write","children":[]}]},{"level":2,"title":"协程库 (coroutine)","slug":"协程库-coroutine","link":"#协程库-coroutine","children":[{"level":3,"title":"coroutine.create(f)","slug":"coroutine-create-f","link":"#coroutine-create-f","children":[]},{"level":3,"title":"coroutine.resume(co [, val1, ...])","slug":"coroutine-resume-co-val1","link":"#coroutine-resume-co-val1","children":[]},{"level":3,"title":"coroutine.running()","slug":"coroutine-running","link":"#coroutine-running","children":[]},{"level":3,"title":"coroutine.status(co)","slug":"coroutine-status-co","link":"#coroutine-status-co","children":[]},{"level":3,"title":"coroutine.wrap(f)","slug":"coroutine-wrap-f","link":"#coroutine-wrap-f","children":[]},{"level":3,"title":"coroutine.yield(...)","slug":"coroutine-yield","link":"#coroutine-yield","children":[]}]},{"level":2,"title":"表库 (table)","slug":"表库-table","link":"#表库-table","children":[{"level":3,"title":"table.concat(list [, sep [, i [, j]])","slug":"table-concat-list-sep-i-j","link":"#table-concat-list-sep-i-j","children":[]},{"level":3,"title":"table.insert(list, [pos,] value)","slug":"table-insert-list-pos-value","link":"#table-insert-list-pos-value","children":[]},{"level":3,"title":"table.maxn(t)","slug":"table-maxn-t","link":"#table-maxn-t","children":[]},{"level":3,"title":"table.remove(list [, pos])","slug":"table-remove-list-pos","link":"#table-remove-list-pos","children":[]},{"level":3,"title":"table.sort(list [, comp])","slug":"table-sort-list-comp","link":"#table-sort-list-comp","children":[]}]},{"level":2,"title":"调试库 (debug)","slug":"调试库-debug","link":"#调试库-debug","children":[{"level":3,"title":"debug.debug()","slug":"debug-debug","link":"#debug-debug","children":[]},{"level":3,"title":"debug.getfenv(object)","slug":"debug-getfenv-object","link":"#debug-getfenv-object","children":[]},{"level":3,"title":"debug.gethook()","slug":"debug-gethook","link":"#debug-gethook","children":[]},{"level":3,"title":"debug.getinfo([thread [, f [, what]])","slug":"debug-getinfo-thread-f-what","link":"#debug-getinfo-thread-f-what","children":[]},{"level":3,"title":"debug.getlocal([thread [, f [, loc]])","slug":"debug-getlocal-thread-f-loc","link":"#debug-getlocal-thread-f-loc","children":[]},{"level":3,"title":"debug.getmetatable(object)","slug":"debug-getmetatable-object","link":"#debug-getmetatable-object","children":[]},{"level":3,"title":"debug.getregistry()","slug":"debug-getregistry","link":"#debug-getregistry","children":[]},{"level":3,"title":"debug.getupvalue(f [, i])","slug":"debug-getupvalue-f-i","link":"#debug-getupvalue-f-i","children":[]},{"level":3,"title":"debug.setfenv(object, table)","slug":"debug-setfenv-object-table","link":"#debug-setfenv-object-table","children":[]},{"level":3,"title":"debug.sethook(hook, mask [, count])","slug":"debug-sethook-hook-mask-count","link":"#debug-sethook-hook-mask-count","children":[]},{"level":3,"title":"debug.setlocal([thread [, f,] level, value)","slug":"debug-setlocal-thread-f-level-value","link":"#debug-setlocal-thread-f-level-value","children":[]},{"level":3,"title":"debug.setmetatable(object, table)","slug":"debug-setmetatable-object-table","link":"#debug-setmetatable-object-table","children":[]},{"level":3,"title":"debug.setupvalue(f [, i,] value)","slug":"debug-setupvalue-f-i-value","link":"#debug-setupvalue-f-i-value","children":[]},{"level":3,"title":"debug.traceback([thread [, message [, level]])","slug":"debug-traceback-thread-message-level","link":"#debug-traceback-thread-message-level","children":[]}]},{"level":2,"title":"位运算库 (bit)","slug":"位运算库-bit","link":"#位运算库-bit","children":[{"level":3,"title":"bit.band(x1, x2 [, ...])","slug":"bit-band-x1-x2","link":"#bit-band-x1-x2","children":[]},{"level":3,"title":"bit.bnot(x)","slug":"bit-bnot-x","link":"#bit-bnot-x","children":[]},{"level":3,"title":"bit.bor(x1, x2 [, ...])","slug":"bit-bor-x1-x2","link":"#bit-bor-x1-x2","children":[]},{"level":3,"title":"bit.bxor(x1, x2 [, ...])","slug":"bit-bxor-x1-x2","link":"#bit-bxor-x1-x2","children":[]},{"level":3,"title":"bit.lshift(x, disp)","slug":"bit-lshift-x-disp","link":"#bit-lshift-x-disp","children":[]},{"level":3,"title":"bit.rshift(x, disp)","slug":"bit-rshift-x-disp","link":"#bit-rshift-x-disp","children":[]},{"level":3,"title":"bit.arshift(x, disp)","slug":"bit-arshift-x-disp","link":"#bit-arshift-x-disp","children":[]},{"level":3,"title":"bit.rol(x, disp)","slug":"bit-rol-x-disp","link":"#bit-rol-x-disp","children":[]},{"level":3,"title":"bit.ror(x, disp)","slug":"bit-ror-x-disp","link":"#bit-ror-x-disp","children":[]},{"level":3,"title":"bit.tobit(x)","slug":"bit-tobit-x","link":"#bit-tobit-x","children":[]}]},{"level":2,"title":"编码库 (enc)","slug":"编码库-enc","link":"#编码库-enc","children":[{"level":3,"title":"enc.base64encode(input)","slug":"enc-base64encode-input","link":"#enc-base64encode-input","children":[]},{"level":3,"title":"enc.base64decode(input)","slug":"enc-base64decode-input","link":"#enc-base64decode-input","children":[]}]},{"level":2,"title":"JSON 库","slug":"json-库","link":"#json-库","children":[{"level":3,"title":"json.encode(table)","slug":"json-encode-table","link":"#json-encode-table","children":[]},{"level":3,"title":"json.decode(string)","slug":"json-decode-string","link":"#json-decode-string","children":[]},{"level":3,"title":"json.null()","slug":"json-null","link":"#json-null","children":[]},{"level":3,"title":"json.parse(string)","slug":"json-parse-string","link":"#json-parse-string","children":[]},{"level":3,"title":"json.stringify(table)","slug":"json-stringify-table","link":"#json-stringify-table","children":[]}]},{"level":2,"title":"包库 (package)","slug":"包库-package","link":"#包库-package","children":[{"level":3,"title":"package.loaded","slug":"package-loaded","link":"#package-loaded","children":[]},{"level":3,"title":"package.loaders","slug":"package-loaders","link":"#package-loaders","children":[]},{"level":3,"title":"package.loadlib(libname [, initfunc])","slug":"package-loadlib-libname-initfunc","link":"#package-loadlib-libname-initfunc","children":[]},{"level":3,"title":"package.path","slug":"package-path","link":"#package-path","children":[]},{"level":3,"title":"package.searchpath(name [, path [, sep [, rep]])","slug":"package-searchpath-name-path-sep-rep","link":"#package-searchpath-name-path-sep-rep","children":[]},{"level":3,"title":"package.seeall([name])","slug":"package-seeall-name","link":"#package-seeall-name","children":[]}]},{"level":2,"title":"使用示例","slug":"使用示例","link":"#使用示例","children":[{"level":3,"title":"交互式 Lua Shell","slug":"交互式-lua-shell","link":"#交互式-lua-shell","children":[]},{"level":3,"title":"执行 Lua 脚本文件","slug":"执行-lua-脚本文件","link":"#执行-lua-脚本文件","children":[]},{"level":3,"title":"系统信息查询","slug":"系统信息查询","link":"#系统信息查询","children":[]},{"level":3,"title":"环境变量操作","slug":"环境变量操作","link":"#环境变量操作","children":[]},{"level":3,"title":"加密和编码","slug":"加密和编码","link":"#加密和编码","children":[]}]},{"level":2,"title":"注意事项","slug":"注意事项","link":"#注意事项","children":[]},{"level":2,"title":"版本信息","slug":"版本信息","link":"#版本信息","children":[]}],"git":{"updatedTime":1770461650000,"contributors":[{"name":"Leonmmcoset","username":"Leonmmcoset","email":"testmod@qq.com","commits":6,"url":"https://github.com/Leonmmcoset"}],"changelog":[{"hash":"c819327f853a004c13ca1f463e369d4369b7391f","time":1770461650000,"email":"testmod@qq.com","author":"Leonmmcoset","message":"更新Lua文档"},{"hash":"33012c48e64dfd0d9488960bc5305feaa64a1cca","time":1770268517000,"email":"testmod@qq.com","author":"Leonmmcoset","message":"GUI测试+Lua增加计时器"},{"hash":"d02fb85b1c8625458e60f9eea59c37544a521f88","time":1770196518000,"email":"testmod@qq.com","author":"Leonmmcoset","message":"json"},{"hash":"33510365f48beba3a56b2dc6afd4c54b1fbdab60","time":1770190333000,"email":"testmod@qq.com","author":"Leonmmcoset","message":"docs&amp;Lua input()"},{"hash":"33afd6f2b50d2185e2c906d8abbc7ddd3f67947f","time":1770185997000,"email":"testmod@qq.com","author":"Leonmmcoset","message":"网络"},{"hash":"0020d125c77f60f3e62911609af9a418daf60bec","time":1770143767000,"email":"testmod@qq.com","author":"Leonmmcoset","message":"Lua更新"}]},"filePathRelative":"lua.md"}');export{c as comp,u as data};
