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

SCRIPT: Add methods for Vivy to get globals and modules

parent 53a264b4
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
......@@ -43,15 +43,14 @@ StdType = enum {
"NUMBER",
"COLOR",
"BOOLEAN",
"STRING",
}
-- Vivy global object construction
os = nil
io = nil
debug = nil
Vivy = { }
Version = { MAJOR = 0, MINOR = 1, PATCH = 0, LABEL = "alpha" }
Vivy["Fun"] = FreeFunctions()
os, io, debug = nil, nil, nil
Vivy = { }
Version = { MAJOR = 0, MINOR = 1, PATCH = 0, LABEL = "alpha" }
Vivy["___Fun"] = FreeFunctions()
Vivy["Version"] = setmetatable(Version, {
__tostring = function ()
......@@ -68,7 +67,18 @@ Vivy["Version"] = setmetatable(Version, {
end
})
-- Standard color creation function
function Vivy:global () return Vivy.___Fun end
function Vivy:module (tbl)
if type(tbl) == "table" and #tbl == 1 then
return Vivy.___Fun.getModule(tbl[1])
elseif type(tbl) == "string" then
return Vivy.___Fun.getModule(tbl)
else
error("Invalid argument, you should pass a single string", 2)
end
end
function Vivy:newColor (colorString)
-- Not implemented
return false
......@@ -81,4 +91,4 @@ Vivy["Vivy"] = Vivy
-- Vivy keyword...
setrometatable(Vivy)
generalize(Iterable)
print = Vivy.Fun.print
print = Vivy.___Fun.print
......@@ -8,13 +8,38 @@ using namespace Vivy::Script;
// FreeFunctions
int
FreeFunctions::print(lua_State *L) noexcept
FreeFunctions::print(lua_State *const L) noexcept
{
const std::string_view arg = CHECK_STRING_VIEW(L, 1);
out(LuaContext::getContext(L)) << "OUT: " << arg << "\n";
LUA_RETURN_NOTHING(L);
}
int
FreeFunctions::getModule(lua_State *const L) noexcept
{
const auto *const context = LuaContext::getContext(L);
const std::string_view modName = CHECK_STRING_VIEW(L, 1);
[[maybe_unused]] const ModuleDeclaration *const mod = context->getModule(modName);
return 1;
}
int
FreeFunctions::start(lua_State *const L) noexcept
{
lua_settop(L, 0);
lua_pushinteger(L, 0);
return 1;
}
int
FreeFunctions::finish(lua_State *const L) noexcept
{
lua_settop(L, 0);
lua_pushinteger(L, 0);
return 1;
}
// ModuleDeclaration
bool
......
......@@ -271,9 +271,15 @@ public:
script_class (FreeFunctions) {
LUA_SCRIPTABLE_CLASS(FreeFunctions)
static int print(lua_State *) noexcept;
static int print(lua_State *const) noexcept;
static int getModule(lua_State *const) noexcept;
static int start(lua_State *const) noexcept;
static int finish(lua_State *const) noexcept;
method_list metaMethods = { luaRegDefaultGC };
method_list methods = { LUA_DECL_METHOD(FreeFunctions, print), LUA_DECL_CREATE(FreeFunctions) };
method_list methods = { LUA_DECL_METHOD(FreeFunctions, getModule),
LUA_DECL_METHOD(FreeFunctions, start),
LUA_DECL_METHOD(FreeFunctions, finish),
LUA_DECL_METHOD(FreeFunctions, print), LUA_DECL_CREATE(FreeFunctions) };
};
}
......@@ -14,7 +14,7 @@ module:export { "printFoo", function () prettyPrint ("Bar") end }
module:export { "retime_lines", LINE, function (opt, line)
line.start = line.start + opt.preTime
line.finish = line.finish + opt.postTime
if line.start <= 0 then line.start = 0 end
if line.start <= global:start() then line.start = global:start() end
if line.finish >= global:finish() then line.finish = global:finish() end
return line
end }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter