From 37ac808a4f16a826342964d13443689978bd8542 Mon Sep 17 00:00:00 2001 From: Benoit Germain <benoit.germain@ubisoft.com> Date: Mon, 28 Oct 2024 17:46:27 +0100 Subject: Renamed macros_and_utils.h → macros_and_utils.hpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cancel.h | 2 +- src/compat.cpp | 2 +- src/macros_and_utils.h | 49 ------------------------------------------------ src/macros_and_utils.hpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ src/nameof.h | 2 +- src/state.h | 2 +- src/uniquekey.h | 2 +- 7 files changed, 54 insertions(+), 54 deletions(-) delete mode 100644 src/macros_and_utils.h create mode 100644 src/macros_and_utils.hpp (limited to 'src') diff --git a/src/cancel.h b/src/cancel.h index 24fd724..97661f1 100644 --- a/src/cancel.h +++ b/src/cancel.h @@ -1,6 +1,6 @@ #pragma once -#include "macros_and_utils.h" +#include "macros_and_utils.hpp" #include "uniquekey.h" // ################################################################################################# diff --git a/src/compat.cpp b/src/compat.cpp index c6073e3..c332ddc 100644 --- a/src/compat.cpp +++ b/src/compat.cpp @@ -1,7 +1,7 @@ #include "_pch.hpp" #include "compat.hpp" -#include "macros_and_utils.h" +#include "macros_and_utils.hpp" // ################################################################################################# diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h deleted file mode 100644 index 6850ddf..0000000 --- a/src/macros_and_utils.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "debug.hpp" -#include "luaerrors.hpp" -#include "unique.hpp" - -using namespace std::chrono_literals; - -// ################################################################################################# - -inline void STACK_GROW(lua_State* L_, int n_) -{ - if (!lua_checkstack(L_, n_)) { - raise_luaL_error(L_, "Cannot grow stack!"); - } -} - -// ################################################################################################# - -#define LUAG_FUNC(func_name) int LG_##func_name(lua_State* const L_) - -// ################################################################################################# - -using lua_Duration = std::chrono::template duration<lua_Number>; - -// ################################################################################################# - -DECLARE_UNIQUE_TYPE(SourceState, lua_State*); -DECLARE_UNIQUE_TYPE(DestState, lua_State*); - -// ################################################################################################# - -// A helper to issue an error if the provided optional doesn't contain a value -// we can't use std::optional::value_or(luaL_error(...)), because the 'or' value is always evaluated -template <typename T> -concept IsOptional = requires(T x) -{ - x.value_or(T{}); -}; - -template <typename T, typename... Ts> -requires IsOptional<T> -typename T::value_type const& OptionalValue(T const& x_, Ts... args_) -{ - if (!x_.has_value()) { - raise_luaL_error(std::forward<Ts>(args_)...); - } - return x_.value(); -} diff --git a/src/macros_and_utils.hpp b/src/macros_and_utils.hpp new file mode 100644 index 0000000..6850ddf --- /dev/null +++ b/src/macros_and_utils.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include "debug.hpp" +#include "luaerrors.hpp" +#include "unique.hpp" + +using namespace std::chrono_literals; + +// ################################################################################################# + +inline void STACK_GROW(lua_State* L_, int n_) +{ + if (!lua_checkstack(L_, n_)) { + raise_luaL_error(L_, "Cannot grow stack!"); + } +} + +// ################################################################################################# + +#define LUAG_FUNC(func_name) int LG_##func_name(lua_State* const L_) + +// ################################################################################################# + +using lua_Duration = std::chrono::template duration<lua_Number>; + +// ################################################################################################# + +DECLARE_UNIQUE_TYPE(SourceState, lua_State*); +DECLARE_UNIQUE_TYPE(DestState, lua_State*); + +// ################################################################################################# + +// A helper to issue an error if the provided optional doesn't contain a value +// we can't use std::optional::value_or(luaL_error(...)), because the 'or' value is always evaluated +template <typename T> +concept IsOptional = requires(T x) +{ + x.value_or(T{}); +}; + +template <typename T, typename... Ts> +requires IsOptional<T> +typename T::value_type const& OptionalValue(T const& x_, Ts... args_) +{ + if (!x_.has_value()) { + raise_luaL_error(std::forward<Ts>(args_)...); + } + return x_.value(); +} diff --git a/src/nameof.h b/src/nameof.h index 0e15a70..6709a16 100644 --- a/src/nameof.h +++ b/src/nameof.h @@ -1,5 +1,5 @@ #pragma once -#include "macros_and_utils.h" +#include "macros_and_utils.hpp" LUAG_FUNC(nameof); diff --git a/src/state.h b/src/state.h index a6bb43b..ecf1ce8 100644 --- a/src/state.h +++ b/src/state.h @@ -1,7 +1,7 @@ #pragma once #include "debugspew.h" -#include "macros_and_utils.h" +#include "macros_and_utils.hpp" // forwards enum class LookupMode; diff --git a/src/uniquekey.h b/src/uniquekey.h index 693a27a..9041363 100644 --- a/src/uniquekey.h +++ b/src/uniquekey.h @@ -1,7 +1,7 @@ #pragma once #include "compat.hpp" -#include "macros_and_utils.h" +#include "macros_and_utils.hpp" // ################################################################################################# -- cgit v1.2.3-55-g6feb