注册

注册 涵盖了以下内容:使你自己编写的Lua脚本Automation 4 Lua出现在Aegisub中、 提供和脚本有关的信息、该脚本提供了什么样的 特性

有关特性(Feature)的解释

Automation 4 中的一个最基础的概念就是 特性 。特性决定了Aegisub如何响应用户的动作去调用脚本。

特性不是简单的回调。它通常是一组几个回调函数,以及如何在GUI中向用户呈现它们的一些信息。

一种特性的类型是 macro (宏),宏会被作为一个小项展示在自动化菜单中,它有一个名字(即菜单中显示的内容), 一段描述(当鼠标悬停在该项时,状态栏显示的说明文本),一个处理函数(当用户点按该项时执行的函数) 还有一个可选的有效性确认函数(决定这个宏在当前状态下是否可以运行,如:卡拉OK模板执行器就具有这个属性,如果检测不到template行,该项为灰色不可用)

另外一种特性是 export filter(导出滤镜)。导出滤镜会被展示在Export 对话框中,在进行导出操作时被应用 导出滤镜也有名字、描述、处理函数,同时提供了配置面板函数。使用配置面板函数可以返回一个配置面板对话框, 在执行导出滤镜的时候会被展示给用户,在配置面板中输入的参数和配置可以传递给处理函数作为参数。

全局脚本信息变量

一个脚本中,可以设置一些全局变量,来给Aegisub提供一些元数据。 这些全局变量会被展示在Automation Manager 对话框中和脚本信息对话框中。

上述的变量均为可选项,即使一个脚本头部没有定义这些变量,Aegisub也会调取文件名来显示。

注册函数

注册函数是指一些Automation 4 提供的现成 Lua 函数,可以方便你把一项特性变为Aegisub可用的形式 你经常会在顶部或者底部调用它。

aegisub.register_macro

摘要: aegisub.register_macro(name, description, processing_function, validation_function, is_active_function)

将脚本注册成为一个具有marco(宏)特性的项。

aegisub.register_filter

摘要: aegisub.register_filter(name, description, priority, processing_function, configuration_panel_provider)

将脚本注册成为一个具有filter(滤镜)特性的项。

Feature callback functions

These are the callback functions you provide to the registration functions.

Macro processing function

Signature: process_macro(subtitles, selected_lines, active_line)

Macro processing functions passed to `aegisub.register_macro` must have this signature. The name process_macro is a placeholder for your own function name.

Return value: The macro processing function can return up to two values: a new selected_lines table containing indices of the lines to select after the macro returns, and an index of the line to make the new active_line. If set, the new active line index must be one of the lines in the new selected_lines table.

Macro validation function

Signature: validate_macro(subtitles, selected_lines, active_line)

Macro validation functions passed to `aegisub.register_macro` must have this signature. The name validate_macro is a placeholder for your own function name.

Important, execution time: Validation functions should always run very fast. Do as little work as possible inside this function, because it is run every time the user pulls open the Automation menu, and every millisecond you spend in validate_macro is one millisecond delay in opening the menu. Consider that the user might have very large files open. Don't block the UI.

Return value: Boolean, true if the macro can run given the current state of subtitles, selected_lines and active_line, false if it can not.

In addition to the primary return value, the validation function can return a string. If it does, the description of the macro is set to the string. This is intended for reporting information to the user about why the macro cannot be run, but there may be more uses for it.

Export filter processing function

Signature: process_filter(subtitles, settings)

Export filter processing functions passed to `aegisub.register_filter` must have this signature. The name process_filter is a placeholder for your own function name.

You do not have to worry about undo issues with export filters. You always work on a copy of the subtitle file.

Return value: Nothing.

Export filter configuration panel provider

Signature: get_filter_configuration_panel(subtitles, old_settings)

Export filter configuration panel providers passed to `aegisub.register_filter` must have this signature. The name get_filter_configuration_panel is a placeholder for your own function name.

Important, execution time: This function is called automatically when the user opens the Export dialogue, and Aegisub blocks until it returns with a configuration panel. Consider that the user might have a very large file open, and that every millisecond spent creating your configuration dialogue is one more millisecond the user has to wait for the Export dialogue to open. Don't block the UI.

Return value: A configuration dialogue table. See the page on configuration dialogues for more information on the format of this table.