Automation 3 self-reload trick

From Aegisub Wiki

Jump to: navigation, search

Making Automation 3 scripts automatically reload themselves with the include function.

If you have a script file named foo.lua, the general form is this:

function process_lines(meta, styles, lines, config)
    include("foo.lua")
    return real_process_lines(meta, styles, lines, config)
end

function real_process_lines(meta, styles, lines, config)
    -- Put what would usually be in process_lines here
end

If you want to use this with Karaskel, it looks like this:

include("karaskel.lua")

function process_lines(meta, styles, lines, config)
    include("foo.lua")
    return karaskel.process_lines(meta, styles, lines, config)
end

Note that the name, description, config, version and kind global variables are left out of these examples for readability. You'll of course still need those.

[edit] How it works

Simple enough, when the script includes itself, all global function definitions are overridden with the new ones read from disk. When you then call the global real_process_lines function, it's the newly updated one you call. This is why the additional function call is required.

[edit] What won't work

The internal information about the script stored in Aegisub won't be updated like this, so if you change the name or description of the script, or change the config, those won't be updated accordingly. You need to use the real Reload button in Automation Manager to update those.

Personal tools