<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.factorio.com/index.php?action=history&amp;feed=atom&amp;title=Tutorial%3AScript_interfaces%2Fzh</id>
	<title>Tutorial:Script interfaces/zh - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.factorio.com/index.php?action=history&amp;feed=atom&amp;title=Tutorial%3AScript_interfaces%2Fzh"/>
	<link rel="alternate" type="text/html" href="https://wiki.factorio.com/index.php?title=Tutorial:Script_interfaces/zh&amp;action=history"/>
	<updated>2026-05-16T23:37:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://wiki.factorio.com/index.php?title=Tutorial:Script_interfaces/zh&amp;diff=218482&amp;oldid=prev</id>
		<title>Cardinal: Translation verification.</title>
		<link rel="alternate" type="text/html" href="https://wiki.factorio.com/index.php?title=Tutorial:Script_interfaces/zh&amp;diff=218482&amp;oldid=prev"/>
		<updated>2026-05-13T19:31:47Z</updated>

		<summary type="html">&lt;p&gt;Translation verification.&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:31, 13 May 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Languages}}{{Translation verification|revisionID=&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;211913&lt;/del&gt;}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Languages}}{{Translation verification|revisionID=&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;217438&lt;/ins&gt;}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 脚本接口（Lua远程调试） ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 脚本接口（Lua远程调试） ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki-wiki:diff:1.41:old-216628:rev-218482:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Cardinal</name></author>
	</entry>
	<entry>
		<id>https://wiki.factorio.com/index.php?title=Tutorial:Script_interfaces/zh&amp;diff=216628&amp;oldid=prev</id>
		<title>Cardinal: Fixed category.</title>
		<link rel="alternate" type="text/html" href="https://wiki.factorio.com/index.php?title=Tutorial:Script_interfaces/zh&amp;diff=216628&amp;oldid=prev"/>
		<updated>2025-12-09T03:44:32Z</updated>

		<summary type="html">&lt;p&gt;Fixed category.&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 03:44, 9 December 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l95&quot;&gt;Line 95:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 95:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* selected_prototype :: [https://lua-api.factorio.com/latest/concepts/SelectedPrototypeData.html SelectedPrototypeData]（可选）：当 [https://lua-api.factorio.com/latest/prototypes/CustomInputPrototype.html#include_selected_prototype include_selected_prototype] 的值为“true”时显示选中原型的信息。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* selected_prototype :: [https://lua-api.factorio.com/latest/concepts/SelectedPrototypeData.html SelectedPrototypeData]（可选）：当 [https://lua-api.factorio.com/latest/prototypes/CustomInputPrototype.html#include_selected_prototype include_selected_prototype] 的值为“true”时显示选中原型的信息。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:&lt;/del&gt;Modding&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{C|&lt;/ins&gt;Modding&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;}}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki-wiki:diff:1.41:old-216627:rev-216628:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Cardinal</name></author>
	</entry>
	<entry>
		<id>https://wiki.factorio.com/index.php?title=Tutorial:Script_interfaces/zh&amp;diff=216627&amp;oldid=prev</id>
		<title>Cardinal: Init translation.</title>
		<link rel="alternate" type="text/html" href="https://wiki.factorio.com/index.php?title=Tutorial:Script_interfaces/zh&amp;diff=216627&amp;oldid=prev"/>
		<updated>2025-12-09T03:42:15Z</updated>

		<summary type="html">&lt;p&gt;Init translation.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Languages}}{{Translation verification|revisionID=211913}}&lt;br /&gt;
== 脚本接口（Lua远程调试） ==&lt;br /&gt;
&lt;br /&gt;
脚本接口允许在同时运行的脚本之间直接进行通信，此功能通过定义一个具有给定函数的公共接口来完成。所有关于接口通信的代码都位于命名空间&amp;lt;code&amp;gt;remote&amp;lt;/code&amp;gt; 中。更多信息请参阅官方API文档。（基于[https://lua-api.factorio.com/latest/classes/LuaRemote.html Lua远程通讯]模式）&lt;br /&gt;
&lt;br /&gt;
=== 定义接口 ===&lt;br /&gt;
&lt;br /&gt;
接口定义如下：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;-- 假定 interface_name 和 table_of_functions 已被定义&lt;br /&gt;
remote.add_interface(interface_name, table_of_functions)&lt;br /&gt;
&lt;br /&gt;
-- 可以在调用过程内部定义 name 和 table &lt;br /&gt;
remote.add_interface(&amp;quot;my_interface&amp;quot;, {&lt;br /&gt;
    my_getter = function()&lt;br /&gt;
        -- 可以从脚本中返回一个或多个变量&lt;br /&gt;
        return &amp;quot;foo&amp;quot;&lt;br /&gt;
    end,&lt;br /&gt;
  &lt;br /&gt;
    -- 值的类型只能是基本类型或（嵌套）表&lt;br /&gt;
    my_setter = function(foo, bar)&lt;br /&gt;
        global.foo = foo&lt;br /&gt;
        global.bar = bar&lt;br /&gt;
    end&lt;br /&gt;
})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
接口函数不接受函数指针或闭包函数。基本类型，Lua对象和数据表均可正常工作。&lt;br /&gt;
&lt;br /&gt;
=== 调用接口函数 ===&lt;br /&gt;
&lt;br /&gt;
接口可用于从不同脚本间调用函数。&amp;#039;&amp;#039;&amp;#039;限制&amp;#039;&amp;#039;&amp;#039;：带有元素的数据表在传递给远程模组时，其中的元素不会被保留（但被传递的游戏对象会被完整保留）。远程模组接收到的数据表是原始表的&amp;#039;&amp;#039;&amp;#039;副本&amp;#039;&amp;#039;&amp;#039;。两个模组&amp;#039;&amp;#039;&amp;#039;不能&amp;#039;&amp;#039;&amp;#039;通过远程调用“共享”同一个数据表。&lt;br /&gt;
&lt;br /&gt;
示例（在上述不同脚本中）：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;-- 调用上述脚本中的 my_interface.my_getter 并输出返回的值&lt;br /&gt;
print(remote.call(&amp;quot;my_interface&amp;quot;, &amp;quot;my_getter&amp;quot;))&lt;br /&gt;
-- 远程调用获取接口名称、函数名称和变量参数&lt;br /&gt;
remote.call(&amp;quot;my_interface&amp;quot;, &amp;quot;my_setter&amp;quot;, 5, {bar=baz})&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 发现接口 ===&lt;br /&gt;
&lt;br /&gt;
脚本可以通过 &amp;lt;code&amp;gt;remote.interfaces&amp;lt;/code&amp;gt; 数据表检查所需的接口及其功能。这是一个按接口名称索引的数据表，其中的值是特定接口的函数集。&lt;br /&gt;
&lt;br /&gt;
示例：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- 检查 &amp;quot;my_interface&amp;quot; 接口是否存在，以及该接口是否包含 &amp;quot;my_getter&amp;quot; 函数&lt;br /&gt;
if remote.interfaces.my_interface and remote.interfaces.my_interface.my_getter then&lt;br /&gt;
    -- 该函数可以安全地远程调用&lt;br /&gt;
end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 自定义输入 ==&lt;br /&gt;
&lt;br /&gt;
在脚本中也可以创建按键绑定。首先需要在数据阶段定义案件绑定，详情可参见 [https://lua-api.factorio.com/latest/prototypes/CustomInputPrototype.html CustomInputPrototype]（官方文档，英文）：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;local button={&lt;br /&gt;
    type = &amp;quot;custom-input&amp;quot;,&lt;br /&gt;
    name = &amp;quot;my-custom-input&amp;quot;,&lt;br /&gt;
    key_sequence = &amp;quot;SHIFT + G&amp;quot;,&lt;br /&gt;
    consuming = &amp;quot;none&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
data:extend{button}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
其中，“consuming”的可用选项有：&lt;br /&gt;
* none：若未定义，则使用默认值&lt;br /&gt;
* game-only：使用相同的按键序列阻止游戏输入，但允许其它自定义输入使用相同的按键序列进行触发。&lt;br /&gt;
&lt;br /&gt;
:&amp;#039;&amp;#039;参见 [https://lua-api.factorio.com/latest/types/ConsumingType.html ConsumingType]（官方文档，英文）&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
区域定义：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;[controls] -- “游戏菜单 -&amp;gt; 按键 -&amp;gt; 模组”菜单显示的文字&lt;br /&gt;
my-custom-input=Potato controls&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
使用 &amp;lt;code&amp;gt;__CONTROL__my-custom-input__&amp;lt;/code&amp;gt; 获取其它区域中的按键绑定，例如&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;this-is-some-locale=Potato controls are bound to &amp;quot;__CONTROL__my-custom-input__&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
在游戏中显示 &amp;lt;code&amp;gt;Potato controls are bound to &amp;quot;SHIFT + G&amp;quot;&amp;lt;/code&amp;gt;。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
然后即可通过订阅对应自定义输入名称的事件，在运行时进行调用：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;script.on_event(&amp;quot;my-custom-input&amp;quot;, function(event)&lt;br /&gt;
    game.print(&amp;quot;Ran on tick: &amp;quot; .. tostring(event.tick))&lt;br /&gt;
end)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
该[https://lua-api.factorio.com/latest/events.html#CustomInputEvent 事件]包含以下内容：&lt;br /&gt;
&lt;br /&gt;
* player_index :: [https://lua-api.factorio.com/latest/concepts/uint.html uint]（无符号整数）&lt;br /&gt;
* tick :: [https://lua-api.factorio.com/latest/concepts/uint.html uint]（无符号整数）&lt;br /&gt;
* input_name :: [https://lua-api.factorio.com/latest/types/string.html string]: 自定义输入的名称。&lt;br /&gt;
* cursor_position :: [https://lua-api.factorio.com/latest/concepts/MapPosition.html MapPosition]：输入被激活时鼠标指针的位置。&lt;br /&gt;
* cursor_direction :: [https://lua-api.factorio.com/latest/defines.html#defines.direction defines.direction] （可选）：当鼠标指针包含可旋转实体时的指针方向。&lt;br /&gt;
* cursor_display_location :: [https://lua-api.factorio.com/latest/concepts/GuiLocation.html GuiLocation]：自定义输入被激活时，显示鼠标指针位置。&lt;br /&gt;
* selected_prototype :: [https://lua-api.factorio.com/latest/concepts/SelectedPrototypeData.html SelectedPrototypeData]（可选）：当 [https://lua-api.factorio.com/latest/prototypes/CustomInputPrototype.html#include_selected_prototype include_selected_prototype] 的值为“true”时显示选中原型的信息。&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Cardinal</name></author>
	</entry>
</feed>