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

SCRIPT: Update specification and lib

parent 6b6810e3
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
......@@ -5,88 +5,74 @@
includes some exposed Vivy API things, enums and object to the user.
]]
function getrometatable(tbl, tablename)
local errormsg = tablename ~= nil
and "attempt to update " .. tablename .. " table"
or "attempt to update a read only table"
return {
__index = tbl,
__metatable = false,
__newindex = function (t, k, v)
error(errormsg, 2)
end
}
end
function setrometatable(tbl, tblname) setmetatable(tbl, getrometatable(tbl, tblname)) end
function generalize(tbl) for k, v in pairs(tbl) do _G[k] = v end end
-- Create an enum
function enum(tbl)
local length = #tbl
for i = 1, length do
local v = tbl[i]
tbl[v] = i
local newval = v .. "_" .. i
tbl[v] = newval
end
local mt = {
__index = tbl,
__newindex = function (t, k, v)
error("attempt to update an enum table", 2)
end
}
setmetatable(tbl, mt)
setrometatable(tbl, "an enum")
return tbl
end
-- Check if a table contains a key
function tableHasKey(tbl, key)
return tbl[key] ~= nil
end
-- Things used to iterate over with a job
-- Enums
Iterable = enum {
"LINE",
"SYLLABE"
"SYLLABE",
}
-- Table: ReservedKeywords["keyword"] = "type"
local ReservedKeywords = {
["Vivy"] = "table"
StdType = enum {
"NUMBER",
"COLOR",
"BOOLEAN",
}
-- Vivy global object construction
Vivy = {
-- Standard libraries
["math"] = math,
["string"] = string,
["utf8"] = utf8,
["table"] = table,
["print"] = print,
-- Custom things
["Iterable"] = Iterable,
}
os = nil
io = nil
debug = nil
Vivy = { }
Version = { MAJOR = 0, MINOR = 1, PATCH = 0, LABEL = "alpha" }
Vivy["Fun"] = FreeFunctions()
version = {
["MAJOR"] = 0,
["MINOR"] = 1,
["PATCH"] = 0,
["LABEL"] = "alpha",
}
Vivy["Version"] = setmetatable(version, {
Vivy["Version"] = setmetatable(Version, {
__tostring = function ()
return string.format("%d.%d.%d-%s",
Vivy.Version.MAJOR,
Vivy.Version.MINOR,
Vivy.Version.PATCH,
Vivy.Version.LABEL)
Version.MAJOR,
Version.MINOR,
Version.PATCH,
Version.LABEL)
end,
__index = Version,
__metatable = false,
__newindex = function (t, k, v)
error("attempt to update the version table", 2)
end
})
-- In case we are able to do the _ENV <- Vivy one day...
Vivy["Vivy"] = Vivy
Vivy = setmetatable(Vivy, {
__newindex = function (t, k, v)
error("you can't set new keys in the Vivy table")
end
})
-- Hide everything from the user, appart some specific things he can do.
local _ENV = setmetatable(Vivy, {
__newindex = function (t, k, v)
-- Use the ReservedKeywords table here
if (tableHasKey(ReservedKeywords, k)) then
error("The keyword " .. k .. " is protected!")
else
rawset(t, k, v)
end
end
})
-- Protect the content of Vivy, for now we are unable to protect the
-- Vivy keyword...
setrometatable(Vivy)
generalize(Iterable)
print = Vivy.Fun.print
-- vim: ft=lua
local global = Vivy:global { }
local module = Vivy:module { "sample-spec" }
global = Vivy:global { }
module = Vivy:module { "sample-spec" }
local utils = module:import { "utils" }
local prettyPrint = module:import { "utils", "prettyPrint" }
utils = module:import { "utils" }
prettyPrint = module:import { "utils", "prettyPrint" }
local tripleCopySyl = module:export { "tripleCopySyl", function (syl)
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", Iterable.LINE, function (opt, line)
module:export { "retime_lines", LINE, function (opt, line)
line.start += opt.preTime
line.finish += opt.postTime
if line.start <= 0 then line.start = 0 end
......@@ -19,7 +19,7 @@ module:export { "retime_lines", Iterable.LINE, function (opt, line)
return line
end }
module:export { "create_syllabes", Iterable.SYLLABE, function (opt, syl)
module:export { "create_syllabes", SYLLABE, function (opt, syl)
local newSyls = tripleCopySyl(syl)
newSyls[1].start = syl.line.start
newSyls[1].finish = syl.start
......
-- vim: ft=lua
local custom_opt = DeclareOption { option1 = false }
local time_opt = DeclareOption { preTime = -900, postTime = 300, }
local color_opt = DeclareOption { color1 = Vivy:newColor("#314159") }
custom_opt = DeclareOption { option1 = false }
time_opt = DeclareOption { preTime = -900, postTime = 300, }
color_opt = DeclareOption { color1 = Vivy:newColor("#314159") }
DeclareModule {
name = "sample-spec",
......@@ -17,8 +17,8 @@ DeclareModule {
ImportFunction { "utils", "prettyPrint" },
},
jobs = {
DeclareJob { name = "set_retime", options = { time_opt } },
DeclareJob { name = "demultiply_syllabes" },
ImportJob { name = "color_after_read_3", script = "utils", options = { color_opt } }
DeclareJob { "set_retime", options = { time_opt } },
DeclareJob { "demultiply_syllabes" },
ImportJob { "utils", "color_after_read_3", 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