Skip to content

Add a way to execute a Lua file with Vivy in a click-click way

Kubat requested to merge lua-exec into master

Overview

Add the module creation to Vivy. We will see later to apply a module to a .vivy file (with the options found in the .vivy etc).

We now have one file for a script. The .module file that describes the script, the job to do in what order and the different free functions. The .module file also have the different option type declaration for inter-script job reuse.

Sample script for now:

--- Declaration

local custom_opt = DeclareOption { option1 = false }
local time_opt   = DeclareOption { preTime = -900, postTime = 300, }
local color_opt  = DeclareOption { color1 = Vivy:newColor("#314159") }

local module = DeclareModule {
    name        = "sample-spec",
    description = "Sample script used for the specification proposition",
    author      = "Vivy",
    revision    = "rev-1254",
    imports     = { "utils" },
    options     = { custom_opt, time_opt, color_opt },
    functions   = {
        DeclareFunction { "tripleCopySyl" },
        DeclareFunction { "printFoo" },
        ImportFunction  { "utils", "prettyPrint" },
    },
    jobs = {
        DeclareJob { "set_retime", options = { time_opt } },
        DeclareJob { "demultiply_syllabes" },
        ImportJob  { "utils", "color_after_read_3", "utils", options = { color_opt } }
    }
}

--- Implementation

local utils       = module:import { "utils" }
local prettyPrint = module:import { "utils", "prettyPrint" }

local tripleCopySyl = module:export { "tripleCopySyl", function (syl)
    return { syl:copy(), syl:copy(), syl:copy() }
end }

module:export { "printFoo", function () prettyPrint ("Bar") end }

module:export { "retime_lines", LINE, function (opt, line)
    line.start  = line.start + opt.preTime
    line.finish = line.start + opt.postTime
    if line.start <= 0 then line.start = 0 end
    if line.finish >= Vivy:finish() then line.finish = Vivy:finish() end
    return line
end }

module:export { "create_syllabes", 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
    return newSyls
end }

-- vim: ft=lua

The minimal small boi:

DeclareModule {
    name        = [[ sample-spec ]],
    author      = [[ Vivy ]]
}

What this MR does

It add the .module script support and creation of the module for a script.

What this MR doesn't do

It doesn't apply a script / module to a vivy file as the vivy file is not available for now.

The multimodule is not available for now.

Edited by Kubat

Merge request reports