From c31dbbd0936b32a3fa6f7a24af0524910fa45fd4 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Thu, 24 Oct 2024 22:21:22 +0200 Subject: [PATCH] Added utility functions to check type of script values. --- source/mijin/types/script_value.hpp | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/source/mijin/types/script_value.hpp b/source/mijin/types/script_value.hpp index 4144c67..f2e0bf5 100644 --- a/source/mijin/types/script_value.hpp +++ b/source/mijin/types/script_value.hpp @@ -85,6 +85,48 @@ public: std::partial_ordering operator<=>(const ScriptValue& other) const = default; + [[nodiscard]] + bool isUndefined() const noexcept + { + return std::holds_alternative(base_); + } + + [[nodiscard]] + bool isBool() const noexcept + { + return std::holds_alternative(base_); + } + + [[nodiscard]] + bool isInteger() const noexcept + { + return std::holds_alternative(base_); + } + + [[nodiscard]] + bool isFloat() const noexcept + { + return std::holds_alternative(base_); + } + + [[nodiscard]] + bool isString() const noexcept + { + return std::holds_alternative(base_); + } + + [[nodiscard]] + bool isArray() const noexcept + { + return std::holds_alternative(base_); + } + + [[nodiscard]] + bool isMap() const noexcept + { + return std::holds_alternative(base_); + } + template auto visit(TFunction&& function) const {