<?xml version="1.0" encoding="gbk"?>
<rss version="2.0">
  <channel>
    <title>曲径通幽论坛 - 『LUA』</title>
    <link>http://www.groad.net/bbs/forum.php?mod=forumdisplay&amp;fid=254</link>
    <description>Latest 20 threads of 『LUA』</description>
    <copyright>Copyright(C) 曲径通幽论坛</copyright>
    <generator>Discuz! Board by Comsenz Inc.</generator>
    <lastBuildDate>Mon, 25 May 2026 02:54:23 +0000</lastBuildDate>
    <ttl>60</ttl>
    <image>
      <url>http://www.groad.net/bbs/static/image/common/logo_88_31.gif</url>
      <title>曲径通幽论坛</title>
      <link>http://www.groad.net/bbs/</link>
    </image>
    <item>
      <title>table.remove</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8812</link>
      <description><![CDATA[table.remove 从 table 中移除元素，默认情况下它是从最后一个开始移除的，如下代码所示：

运行输出：


可以通过指定第 2 个参数告诉函数移除什么位置上的元素：

输出结果：]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Sat, 03 Jan 2015 09:19:05 +0000</pubDate>
    </item>
    <item>
      <title>table.concat</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8805</link>
      <description><![CDATA[table.concat 函数可以将数组中的字符串连接起来成为一个字符串，比如：

那么运行后输出结果就为 www.groad.net 。

table.concat 还能接受第 2 个参数，一般该参数可用来作为分隔符，参考下面代码：

输出结果为 www.groad.net 

一般情况下都是将所有的字符 ...]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Sat, 27 Dec 2014 08:54:27 +0000</pubDate>
    </item>
    <item>
      <title>table.sort 与 table.insert 示例</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8804</link>
      <description><![CDATA[table.sort 用来对 table 进行排序。
table.insert 将元素插入 table 中。

table.sort 简单示例代码：

输出：

table.sort 的第 1 个参数是要进行排序的 table，第 2 个参数是个比对函数，可以是匿名函数；如果返回写成 return (A &lt; B)，那么将元素从小到大排 ...]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Sat, 27 Dec 2014 05:29:42 +0000</pubDate>
    </item>
    <item>
      <title>遍历 table 的方法/泛型 for</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8786</link>
      <description><![CDATA[遍历 table，实际上就是遍历 table 中的键值对(key-value pair) 。

对于一个数组型的 table，使用一个普通的 for 来遍历，比如：

运行输出：


还有更好的方法，使用 ipairs 方法来遍历：

使用 ipairs方法，也用到 for，每一次迭代，都会分别将 table 中的  ...]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Sun, 07 Dec 2014 18:09:00 +0000</pubDate>
    </item>
    <item>
      <title>含有非整数索引 table 的长度</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8785</link>
      <description><![CDATA[如果一个 table 里含有非整数索引时，在使用 # 来计算其长度时，非整数索引部分不被计算在内。

比如：


输出结果为 2 。]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Sun, 07 Dec 2014 02:29:11 +0000</pubDate>
    </item>
    <item>
      <title>upvalues 和 closures</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8784</link>
      <description><![CDATA[upvalues 中文可以称之为外部局部变量，之所以称之为非局部，是因为当函数退出后，它仍然存在（正常情况下，局部变量会随着函数的退出也随之消失，因为函数栈也随之弹出），这说起来有点像 C 中的函数里的静态变量，却又不尽相同。

closures 中文可以称之为闭合函数 ...]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Sat, 06 Dec 2014 11:35:57 +0000</pubDate>
    </item>
    <item>
      <title>函数的多重返回值</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8763</link>
      <description><![CDATA[假设有下面的函数：


比较下面的例子：

输出结果：


输出结果：

返回值个数和接收变量的个数相等时：

输出结果：

[hr]

输出结果：


输出结果：

不像想象中的那样输出  1    2   3   a 。


输出结果：

规则：如果一个有多个返回值 ...]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Sun, 23 Nov 2014 15:55:44 +0000</pubDate>
    </item>
    <item>
      <title>匿名函数与高阶函数</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8762</link>
      <description><![CDATA[一个函数接受另一个函数作为实参的，称其是一个 “高阶函数” (higher-order function)。

LUA 将函数视为 “第一类值”，高阶函数也不例外。所谓第一类值，就是说 LUA 中函数与其他传统类型的值具有相同的权利，如函数也可以存储到变量中（无论是全局变量还是局部变 ...]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Sat, 22 Nov 2014 03:57:56 +0000</pubDate>
    </item>
    <item>
      <title>pairs 和 ipairs</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8757</link>
      <description><![CDATA[Lua 的基础库中提供了 pairs 和 ipars 两个函数，它们分别用于遍历 table 和 数组。

这里所说的数组，是索引值为 1,2,3,4...整数的数组，比如下面代码示例：


程序会输出：

在每次循环中，i 会被赋予一个索引值，同时 v 被赋予一个对应于该索引的数组元素值。 ...]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Thu, 20 Nov 2014 05:57:15 +0000</pubDate>
    </item>
    <item>
      <title>运算符的优先级</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8755</link>
      <description><![CDATA[^ 和 .. 是 “右结合” 运算符，其它的都是左结合。]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Sun, 16 Nov 2014 07:51:57 +0000</pubDate>
    </item>
    <item>
      <title>取模运算</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8751</link>
      <description><![CDATA[Lua 5.1 中新增了取模运算，下面来看几个具体的实例。

对于整数来说，a % b 的计算结果的符号永远和第 2 个参数相同。比如 5 % -2 ，那么结果为 -1；如果是  -5 % 2，结果为 1 。

实际上，取模操作是根据下面的规则定义的：

floor() 是向下取整函数。

对于 ...]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Mon, 10 Nov 2014 00:37:16 +0000</pubDate>
    </item>
    <item>
      <title>table 类型</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8746</link>
      <description><![CDATA[使用 {} 创建 table , 比如：

a 通过 key 来索引，比如：


运行结果为：

其中，x 是一个 key，可称之为键。

可以直接将 a 复制给另外一个变量，如：

运行结果和上面一样。

a[\&quot;x\&quot;] 这种写法，还可以替换为 a.x 这种写法。

注意，a[\&quot;x\&quot;] 和 a[x] 是 ...]]></description>
      <category>『LUA』</category>
      <author>beyes</author>
      <pubDate>Thu, 06 Nov 2014 04:07:43 +0000</pubDate>
    </item>
  </channel>
</rss>