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

SCRIPT: Add a way to attach a VivyDocument to a LuaContext

parent c54d8d6e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
2 requêtes de fusion!24Add script functions to get VivyDocument informations,!21Add clean logs support + dependent MR
Ce commit fait partie de la requête de fusion !22. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
......@@ -49,6 +49,15 @@ LuaContext::getContext(const lua_State *const state) noexcept
return contextList.contains(state) ? contextList.at(state) : nullptr;
}
LuaContext::Code
LuaContext::loadDocument(std::shared_ptr<Vivy::VivyDocument> doc) noexcept
{
if (attachedVivyDocument != nullptr)
return Error;
attachedVivyDocument = doc;
return Success;
}
LuaContext::Code
LuaContext::loadDocument(std::shared_ptr<ScriptDocument> doc) noexcept
{
......
......@@ -47,10 +47,22 @@ ScriptStore::resetLoadedScripts() noexcept
bool
ScriptStore::executeScript(Uuid id) noexcept
{
const auto script = documents.at(id);
const auto &script = documents.at(id);
return luaContext->loadDocument(script) == Code::Success;
}
bool
ScriptStore::executeScript(Uuid id, std::shared_ptr<Vivy::VivyDocument> doc) noexcept
{
if (doc == nullptr)
return false;
if (luaContext->loadDocument(doc) != Script::LuaContext::Success) {
luaContext->setFailedWith("A VivyDocument is already loaded, can't attach a new one");
return false;
}
return executeScript(id);
}
const std::vector<std::string_view>
ScriptStore::getLoadedModules() const noexcept
{
......
#pragma once
#include "../CRTPStore.hh"
#include "../Document/VivyDocument.hh"
#include "ScriptDocument.hh"
#include "LuaContext.hh"
......@@ -27,6 +28,7 @@ public:
void loadScriptFolder(const QString &folderPath);
std::vector<Item> getLoadedScripts() const noexcept;
bool executeScript(Uuid) noexcept;
bool executeScript(Uuid, std::shared_ptr<Vivy::VivyDocument>) noexcept;
QString getLastLuaError() noexcept;
......
......@@ -2,7 +2,9 @@
#include "UI/MainWindow.hh"
#include "UI/DockWidgetTitleBar.hh"
#include "Lib/Document/VivyDocumentStore.hh"
#include "Lib/Document/VivyDocument.hh"
#include "Lib/Script/ScriptStore.hh"
#include "Lib/Script/ScriptDocument.hh"
using namespace Vivy;
......@@ -14,7 +16,25 @@ VivyApplication::VivyApplication(int &argc, char **argv)
VIVY_LOG_CTOR() << "Construction is OK";
if (argc >= 2) {
selectedDoc = scriptStore->loadDocument(QString::fromUtf8(argv[1]));
for (int i = 1; i < argc; ++i) {
const QString passedFileName(QString::fromUtf8(argv[1]));
const QFileInfo passedArgumentFile(passedFileName);
Utils::DocumentType passedFileType;
if (Utils::detectDocumentType(passedArgumentFile, &passedFileType)) {
if (passedFileType == Utils::DocumentType::Vivy) {
selectedVivyDoc = documentStore->loadDocument(passedFileName);
logInfo() << "Select vivy document " << passedFileName;
} else if (passedFileType == Utils::DocumentType::VivyScript) {
selectedScriptDoc = scriptStore->loadDocument(passedFileName);
logInfo() << "Select script document " << passedFileName;
} else {
logError() << "Not handled file type for file " << passedFileName;
}
} else {
logError() << "Unrecognized file type for file " << passedFileName;
}
}
selectedType = ApplicationType::CLI;
VIVY_LOG_CTOR() << "Select the ApplicationType::CLI";
}
......@@ -70,9 +90,12 @@ VivyApplication::exec() noexcept
switch (selectedType) {
case ApplicationType::CLI: {
if ((selectedDoc == nullptr) || (!scriptStore->executeScript(selectedDoc->getUuid())))
if ((selectedVivyDoc == nullptr) || (selectedScriptDoc == nullptr))
return 1;
if (!scriptStore->executeScript(selectedScriptDoc->getUuid(), selectedVivyDoc))
return 2;
for (const auto &str : scriptStore->getLoadedModules()) {
std::cout << "Module " << str << " was loaded!\n";
[[maybe_unused]] const auto *mod = scriptStore->getModule(str);
......
......@@ -49,6 +49,7 @@ class ScriptStore;
class VivyDocumentStore;
class AbstractDocument;
class ScriptDocument;
class VivyDocument;
// Vivy application class
class VivyApplication : public QApplication {
......@@ -87,7 +88,8 @@ private:
ApplicationType selectedType{ ApplicationType::GUI };
// ApplicationType::CLI Only!
std::shared_ptr<ScriptDocument> selectedDoc{ nullptr };
std::shared_ptr<ScriptDocument> selectedScriptDoc{ nullptr };
std::shared_ptr<VivyDocument> selectedVivyDoc{ nullptr };
public:
VivyApplication(int &argc, char **argv);
......
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