--- title: table - 表与方法 summary: 表保存键值对。序列索引通常从 1 开始。object:run(x) 等价于 object.run(object, x):冒号会传入 self。表不会自动获得游戏方法。 section: reference kind: guide status: reference updated: 2026-10-26 tags: ["API","X4"] sources: ["https://wiki.egosoft.com/X4%20Foundations%20Wiki/Modding%20Support/","https://www.lua.org/manual/5.1/manual.html","https://luajit.org/ext_ffi_api.html"] --- ## 含义 表保存键值对。序列索引通常从 1 开始。object:run(x) 等价于 object.run(object, x):冒号会传入 self。表不会自动获得游戏方法。 ## 示例 ```lua local object = {count = 0} function object:add(value) self.count = self.count + value end object:add(2) local values = {"a", "b"} local text = table.concat(values, ", ") ``` **运行效果:** object.count 结肠通过对象作为自我. 这段段没有打印或写日志信息. 显示的值是示例的预期结果. ## 方法与相关调用 | 函数 | 返回 | 用途 | | --- | --- | --- | | [table.concat](wiki:api-standard-table-concat-59959ede) | [`string`](wiki:type-string) | 连接连串或数序元素与分离器. | | [table.insert](wiki:api-standard-table-insert-fdeedf14) | [`none`](wiki:type-results) | 输入一个序列值并移动元素;一个遗漏的位置添加它. | | [table.remove](wiki:api-standard-table-remove-f70112c3) | [`any`](wiki:type-results) \| [`nil`](wiki:type-nil) | 删除和返回一个序列元素,将后来的值转移到最后一个元素. | | [table.sort](wiki:api-standard-table-sort-34b8a577) | [`none`](wiki:type-results) | 排序序列;比较器必须定义一个严格的序列. | | [table.unpack](wiki:api-standard-table-unpack-01fac384) | [`any`](wiki:type-results), ... | 扩展序列范围到多个结果;需要可用的兼容性扩展. |