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

SCRIPT: Place the ScriptOption class in its own file + change .spek to .module...

SCRIPT: Place the ScriptOption class in its own file + change .spek to .module file extension for module declaration
parent faabfe21
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
...@@ -94,63 +94,6 @@ ModuleDeclaration::setJobs(lua_State *L) noexcept ...@@ -94,63 +94,6 @@ ModuleDeclaration::setJobs(lua_State *L) noexcept
return 0; return 0;
} }
// OptionDeclaration
ScriptOption::ScriptOption(const std::string &str) noexcept
: string(str)
, type(Type::String)
{
}
ScriptOption::ScriptOption(const std::string_view str) noexcept
: string(str)
, type(Type::String)
{
}
ScriptOption::ScriptOption(double n) noexcept
: number(n)
, type(Type::Number)
{
}
ScriptOption::ScriptOption(bool b) noexcept
: boolean(b)
, type(Type::Boolean)
{
}
std::string *
ScriptOption::getString() noexcept
{
return type == Type::String ? &string : nullptr;
}
double *
ScriptOption::getNumber() noexcept
{
return type == Type::Number ? &number : nullptr;
}
bool *
ScriptOption::getBoolean() noexcept
{
return type == Type::Boolean ? &boolean : nullptr;
}
std::string_view
ScriptOption::getSignature() const noexcept
{
static constexpr std::string_view signatureNumber = "Number";
static constexpr std::string_view signatureString = "String";
static constexpr std::string_view signatureBoolean = "Boolean";
switch (type) {
case Type::String: return signatureString;
case Type::Number: return signatureNumber;
case Type::Boolean: return signatureBoolean;
}
}
int int
OptionDeclaration::addOptionContent(lua_State *L) noexcept OptionDeclaration::addOptionContent(lua_State *L) noexcept
{ {
......
#pragma once #pragma once
#include "LuaContext.hh" #include "LuaContext.hh"
#include "ScriptOption.hh"
#include "lua.hpp" #include "lua.hpp"
#include <vector> #include <vector>
...@@ -135,30 +136,6 @@ public: ...@@ -135,30 +136,6 @@ public:
} }
}; };
// The options
class ScriptOption {
enum class Type { String, Number, Boolean };
private:
std::string string;
double number;
bool boolean;
Type type;
public:
ScriptOption(const std::string &) noexcept;
ScriptOption(const std::string_view) noexcept;
ScriptOption(bool) noexcept;
ScriptOption(double) noexcept;
std::string *getString() noexcept;
double *getNumber() noexcept;
bool *getBoolean() noexcept;
std::string_view getSignature() const noexcept;
};
// Option declaration // Option declaration
script_class (OptionDeclaration) { script_class (OptionDeclaration) {
LUA_SCRIPTABLE_CLASS(OptionDeclaration) LUA_SCRIPTABLE_CLASS(OptionDeclaration)
......
#include "ScriptOption.hh"
// OptionDeclaration
using namespace Vivy::Script;
ScriptOption::ScriptOption(const std::string &str) noexcept
: string(str)
, type(Type::String)
{
}
ScriptOption::ScriptOption(const std::string_view str) noexcept
: string(str)
, type(Type::String)
{
}
ScriptOption::ScriptOption(double n) noexcept
: number(n)
, type(Type::Number)
{
}
ScriptOption::ScriptOption(bool b) noexcept
: boolean(b)
, type(Type::Boolean)
{
}
std::string *
ScriptOption::getString() noexcept
{
return type == Type::String ? &string : nullptr;
}
double *
ScriptOption::getNumber() noexcept
{
return type == Type::Number ? &number : nullptr;
}
bool *
ScriptOption::getBoolean() noexcept
{
return type == Type::Boolean ? &boolean : nullptr;
}
std::string_view
ScriptOption::getSignature() const noexcept
{
static constexpr std::string_view signatureNumber = "Number";
static constexpr std::string_view signatureString = "String";
static constexpr std::string_view signatureBoolean = "Boolean";
switch (type) {
case Type::String: return signatureString;
case Type::Number: return signatureNumber;
case Type::Boolean: return signatureBoolean;
}
}
#pragma once
#include <string>
#include <string_view>
namespace Vivy::Script
{
// The options
class ScriptOption {
enum class Type { String, Number, Boolean };
private:
std::string string;
double number;
bool boolean;
Type type;
public:
ScriptOption(const std::string &) noexcept;
ScriptOption(const std::string_view) noexcept;
ScriptOption(bool) noexcept;
ScriptOption(double) noexcept;
std::string *getString() noexcept;
double *getNumber() noexcept;
bool *getBoolean() noexcept;
std::string_view getSignature() const noexcept;
};
}
Fichier déplacé
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