Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 75ab8260 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

SCRIPT: Update specification

parent 5804d09d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!16Add a way to execute a Lua file with Vivy in a click-click way
--[[
Sample script to have a Vivy script specification. Note that all things in
a script should be "local" or you won't be saved if you break something
else in Vivy...
-- vim: ft=lua
local global = Vivy:global { }
local script = Vivy:script { "sample-spec" }
local utils = Vivy:import { "utils" }
local prettyPrint = Vivy:import { "utils", "prettyPrint" }
Get the global variables from the Vivy runtime, like the video dimensions
or duration, etc.
local global = Vivy:global()
Get other script, here the util script. You can pass an author in case of
ambiguity. The standard scripts are available under the "std" author, thus
you can't register scripts in the name of "std". If there is ambiguity, an
error will be displayed by Vivy. If the tuple (script, author, revision) is
not unique, you will get an error on register time.
local utils = Vivy:getScript { script = "utils", author = "std" }
Create a new script. All the options and other stuff is defined in the
`.spek` file.
local script = Vivy:newScript {
name = "sample_script", author = "Vivy", revision = "rev-1254"
}
A local function to the script may be used by another script with the
"Vivy:getScript" function call.
All job functions take as first parameter the opt structure. This is really
usefull when calling multiple scripts on the same Vivy document with a
document defined options. The type of the option structure is checked by
Vivy according to the `.spek` file.
]]
local global = Vivy:global()
local utils = Vivy:getScript { script = "utils", author = "std" }
local script = Vivy:newScript {
name = "sample_script",
author = "Vivy",
revision = "rev-1254",
}
Vivy:newFunction ("tripleCopySyl", function (syl)
local tripleCopySyl = Vivy:newFunction ("tripleCopySyl", function (syl)
return { syl:copy(), syl:copy(), syl:copy() }
end)
Vivy:newFunction ("printFoo", function ()
print "Bar"
end)
Vivy:newFunction ("printFoo", function () print "Bar" end)
Vivy:newJob ("retime_lines", Iterable.LINE, function (opt, line)
line.start += opt.preTime
line.finish += opt.postTime
if line.start <= 0 then line.start = 0; end
if line.start <= 0 then line.start = 0 end
if line.finish >= global.finish() then line.finish = global.finish() end
return line
end)
Vivy:newJob ("create_syllabes", Iterable.SYLLABE, function (opt, syl)
local newSyls = tripleCopySyl(syl)
newSyls[1].start = syl.line.start
newSyls[1].finish = syl.start
newSyls[3].finish = syl.line.finish
newSyls[3].start = syl.finish
-- You can return a table, the runtime will unroll it and add all the
-- elements to the new ASS AST.
return newSyls
end)
-- Register the script.
Vivy:registerScript (script)
-- The name and description of the script. Spaces and column `:` characters in
-- the script name are illegal. Comments begin by `--`.
|> sample-spec
#(Sample script use for the specification)
-- Set some usefull informations
file <- sample-spec.lua
author <- Vivy
revision <- rev-1254
-- Register option tipes
#{custom-opt}
optin1 : boolean -> false
#{time-opt}
preTime : integer -> -900
postTime : integer -> 300
#{color-opt}
color1 : color -> Vivy:newColor("#314159")
-- Register used job functions. Here the `sample-spec:` is implied.
@set_retime#{time-opt}
@demultiply_syllabes
@utils:color_after_read_3#{color-opt}
-- Here we have the free functions defined in the script, a comma-separated
-- list, thus comma and spaces and brackets in function names are not allowed.
#[tripleCopySyl, printFoo]
-- vim: ft=
-- vim: ft=lua
DeclareScript {
name = [[ sample-spec ]],
description = [[ Sample script used for the specification proposition ]],
file = [[ sample-spec.lua ]],
author = [[ Vivy ]],
revision = [[ rev-1254 ]],
imports = { "utils" },
options = {
"custom-opt" = { option1 = false },
"time-opt" = { preTime = -900, postTime = 300, },
"color-opt" = { color1 = Vivy:newColor("#314159") }
},
functions = {
DeclareFunctopn { name = "tripleCopySyl" },
DeclareFunction { name = "printFoo" },
ImportFunction { name = "prettyPrint", script = "utils" },
},
jobs = {
DeclareJob { name = "set_retime", options = { "time-opt" } },
DeclareJob { name = "demultiply_syllabes" },
ImportJob { name = "color_after_read_3", script = "utils", options = { "color-opt" } }
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter