mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
✨ Proper read-only pair iteration!
— 🔨 Fix up the general build
This commit is contained in:
parent
b43cee5c9d
commit
002233ba84
|
@ -47,7 +47,7 @@ namespace sol { namespace detail {
|
|||
"`anonymous namespace'" } };
|
||||
|
||||
|
||||
#if SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_) || SOL_IS_ON(SOL_COMPILER_VCXX_CLANG_I_)
|
||||
#if SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_)
|
||||
inline std::string ctti_get_type_name_from_sig(std::string name) {
|
||||
// cardinal sins from MINGW
|
||||
using namespace std;
|
||||
|
|
|
@ -30,23 +30,13 @@
|
|||
|
||||
// clang-format off
|
||||
|
||||
#if defined(SOL_BUILD)
|
||||
#if (SOL_BUILD != 0)
|
||||
#define SOL_BUILD_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_BUILD_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#define SOL_BUILD_I_ SOL_DEFAULT_OFF
|
||||
#endif // Building or not
|
||||
|
||||
#if defined(SOL_DLL)
|
||||
#if (SOL_DLL != 0)
|
||||
#define SOL_DLL_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_DLL_I_ SOL_OFF
|
||||
#endif
|
||||
#elif SOL_IS_ON() && (defined(DLL_) || defined(_DLL))
|
||||
#elif SOL_IS_ON(SOL_COMPILER_VCXX_I_) && (defined(DLL_) || defined(_DLL))
|
||||
#define SOL_DLL_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_DLL_I_ SOL_DEFAULT_OFF
|
||||
|
@ -62,6 +52,18 @@
|
|||
#define SOL_HEADER_ONLY_I_ SOL_DEFAULT_OFF
|
||||
#endif // Header only library
|
||||
|
||||
#if defined(SOL_BUILD)
|
||||
#if (SOL_BUILD != 0)
|
||||
#define SOL_BUILD_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_BUILD_I_ SOL_OFF
|
||||
#endif
|
||||
#elif SOL_IS_ON(SOL_HEADER_ONLY_I_)
|
||||
#define SOL_BUILD_I_ SOL_DEFAULT_OFF
|
||||
#else
|
||||
#define SOL_BUILD_I_ SOL_DEFAULT_ON
|
||||
#endif
|
||||
|
||||
#if defined(SOL_UNITY_BUILD)
|
||||
#if (SOL_UNITY_BUILD != 0)
|
||||
#define SOL_UNITY_BUILD_I_ SOL_ON
|
||||
|
@ -100,7 +102,7 @@
|
|||
#define SOL_API_LINKAGE_I_ __declspec(dllexport)
|
||||
#endif
|
||||
#else
|
||||
#if SOL_IS_ON(SOL_PLATFORM_GCC_I_)
|
||||
#if SOL_IS_ON(SOL_COMPILER_GCC_I_)
|
||||
#define SOL_API_LINKAGE_I_ __attribute__((dllimport))
|
||||
#else
|
||||
#define SOL_API_LINKAGE_I_ __declspec(dllimport)
|
||||
|
@ -153,6 +155,78 @@
|
|||
#define SOL_INTERNAL_FUNC_DEF_I_ SOL_API_LINKAGE_I_
|
||||
#endif
|
||||
|
||||
#if defined(SOL_FUNC_DECL)
|
||||
#define SOL_FUNC_DECL_I_ SOL_FUNC_DECL
|
||||
#elif SOL_IS_ON(SOL_HEADER_ONLY_I_)
|
||||
#define SOL_FUNC_DECL_I_
|
||||
#elif SOL_IS_ON(SOL_DLL_I_)
|
||||
#if SOL_IS_ON(SOL_COMPILER_VCXX_I_)
|
||||
#if SOL_IS_ON(SOL_BUILD_I_)
|
||||
#define SOL_FUNC_DECL_I_ extern __declspec(dllexport)
|
||||
#else
|
||||
#define SOL_FUNC_DECL_I_ extern __declspec(dllimport)
|
||||
#endif
|
||||
#elif SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_)
|
||||
#define SOL_FUNC_DECL_I_ extern __attribute__((visibility("default")))
|
||||
#else
|
||||
#define SOL_FUNC_DECL_I_ extern
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SOL_FUNC_DEFN)
|
||||
#define SOL_FUNC_DEFN_I_ SOL_FUNC_DEFN
|
||||
#elif SOL_IS_ON(SOL_HEADER_ONLY_I_)
|
||||
#define SOL_FUNC_DEFN_I_ inline
|
||||
#elif SOL_IS_ON(SOL_DLL_I_)
|
||||
#if SOL_IS_ON(SOL_COMPILER_VCXX_I_)
|
||||
#if SOL_IS_ON(SOL_BUILD_I_)
|
||||
#define SOL_FUNC_DEFN_I_ __declspec(dllexport)
|
||||
#else
|
||||
#define SOL_FUNC_DEFN_I_ __declspec(dllimport)
|
||||
#endif
|
||||
#elif SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_)
|
||||
#define SOL_FUNC_DEFN_I_ __attribute__((visibility("default")))
|
||||
#else
|
||||
#define SOL_FUNC_DEFN_I_
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SOL_HIDDEN_FUNC_DECL)
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_ SOL_HIDDEN_FUNC_DECL
|
||||
#elif SOL_IS_ON(SOL_HEADER_ONLY_I_)
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_
|
||||
#elif SOL_IS_ON(SOL_DLL_I_)
|
||||
#if SOL_IS_ON(SOL_COMPILER_VCXX_I_)
|
||||
#if SOL_IS_ON(SOL_BUILD_I_)
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_ extern __declspec(dllexport)
|
||||
#else
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_ extern __declspec(dllimport)
|
||||
#endif
|
||||
#elif SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_)
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_ extern __attribute__((visibility("default")))
|
||||
#else
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_ extern
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SOL_HIDDEN_FUNC_DEFN)
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_ SOL_HIDDEN_FUNC_DEFN
|
||||
#elif SOL_IS_ON(SOL_HEADER_ONLY_I_)
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_ inline
|
||||
#elif SOL_IS_ON(SOL_DLL_I_)
|
||||
#if SOL_IS_ON(SOL_COMPILER_VCXX_I_)
|
||||
#if SOL_IS_ON(SOL_BUILD_I_)
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_
|
||||
#else
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_
|
||||
#endif
|
||||
#elif SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_)
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_ __attribute__((visibility("hidden")))
|
||||
#else
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// clang-format on
|
||||
|
||||
#endif // SOL_DETAIL_BUILD_VERSION_HPP
|
||||
|
|
68
include/sol/detail/pairs.hpp
Normal file
68
include/sol/detail/pairs.hpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
// sol2
|
||||
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013-2021 Rapptz, ThePhD and contributors
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this Spermission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#ifndef SOL_DETAIL_PAIRS_HPP
|
||||
#define SOL_DETAIL_PAIRS_HPP
|
||||
|
||||
#include <sol/version.hpp>
|
||||
|
||||
#include <sol/stack.hpp>
|
||||
#include <sol/stack_reference.hpp>
|
||||
|
||||
namespace sol { namespace stack { namespace stack_detail {
|
||||
|
||||
inline int c_lua_next(lua_State* L_) noexcept {
|
||||
stack_reference table_stack_ref(L_, raw_index(1));
|
||||
stateless_stack_reference key_stack_ref(L_, raw_index(2));
|
||||
int result = lua_next(table_stack_ref.lua_state(), table_stack_ref.stack_index());
|
||||
if (result == 0) {
|
||||
stack::push(L_, lua_nil);
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
inline int readonly_pairs(lua_State* L_) noexcept {
|
||||
int pushed = 0;
|
||||
stack::get_field<true, false>(L_, "next");
|
||||
if (!stack::check<unsafe_function>(L_, -1)) {
|
||||
// we do not have the "next" function in the global namespace
|
||||
// from the "table" global entiry, use our own
|
||||
pushed += stack::push(L_, &c_lua_next);
|
||||
}
|
||||
else {
|
||||
pushed += 1;
|
||||
}
|
||||
int metatable_exists = lua_getmetatable(L_, 1);
|
||||
sol_c_assert(metatable_exists == 1);
|
||||
const auto& index_key = to_string(sol::meta_function::index);
|
||||
lua_getfield(L_, lua_gettop(L_), index_key.c_str());
|
||||
lua_remove(L_, -2);
|
||||
pushed += 1;
|
||||
pushed += stack::push(L_, lua_nil);
|
||||
return pushed;
|
||||
}
|
||||
|
||||
}}} // sol::stack::stack_detail
|
||||
|
||||
#endif // SOL_DETAIL_PAIRS_HPP
|
|
@ -302,6 +302,11 @@ namespace sol {
|
|||
}
|
||||
}
|
||||
|
||||
void abandon () noexcept {
|
||||
this->m_error_handler.abandon();
|
||||
base_t::abandon();
|
||||
}
|
||||
|
||||
private:
|
||||
handler_t m_error_handler;
|
||||
|
||||
|
|
|
@ -542,9 +542,10 @@ namespace sol {
|
|||
template <bool read_only = true, typename... Args>
|
||||
table new_enum(const string_view& name, Args&&... args) {
|
||||
table target = create_with(std::forward<Args>(args)...);
|
||||
if (read_only) {
|
||||
table x = create_with(
|
||||
meta_function::new_index, detail::fail_on_newindex, meta_function::index, target, meta_function::pairs, detail::enum_pairs_function);
|
||||
if constexpr (read_only) {
|
||||
// Need to create a special iterator to handle this
|
||||
table x
|
||||
= create_with(meta_function::new_index, detail::fail_on_newindex, meta_function::index, target, meta_function::pairs, stack::stack_detail::readonly_pairs);
|
||||
table shim = create_named(name, metatable_key, x);
|
||||
return shim;
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ namespace sol {
|
|||
template <typename T>
|
||||
table_proxy& operator=(T&& other) & {
|
||||
using Tu = meta::unwrap_unqualified_t<T>;
|
||||
if constexpr (!is_lua_reference_or_proxy_v<Tu> && meta::is_callable_v<Tu>) {
|
||||
if constexpr (!is_lua_reference_or_proxy_v<Tu> && meta::is_invocable_v<Tu>) {
|
||||
return set_function(std::forward<T>(other));
|
||||
}
|
||||
else {
|
||||
|
@ -115,7 +115,7 @@ namespace sol {
|
|||
template <typename T>
|
||||
table_proxy&& operator=(T&& other) && {
|
||||
using Tu = meta::unwrap_unqualified_t<T>;
|
||||
if constexpr (!is_lua_reference_or_proxy_v<Tu> && meta::is_callable_v<Tu> && !detail::is_msvc_callable_rigged_v<T>) {
|
||||
if constexpr (!is_lua_reference_or_proxy_v<Tu> && meta::is_invocable_v<Tu> && !detail::is_msvc_callable_rigged_v<T>) {
|
||||
return std::move(*this).set_function(std::forward<T>(other));
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -273,15 +273,15 @@ namespace sol { namespace meta {
|
|||
namespace meta_detail {
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct is_callable : std::is_function<std::remove_pointer_t<T>> { };
|
||||
struct is_invocable : std::is_function<std::remove_pointer_t<T>> { };
|
||||
|
||||
template <typename T>
|
||||
struct is_callable<T,
|
||||
struct is_invocable<T,
|
||||
std::enable_if_t<std::is_final<unqualified_t<T>>::value && std::is_class<unqualified_t<T>>::value
|
||||
&& std::is_same<decltype(void(&T::operator())), void>::value>> { };
|
||||
|
||||
template <typename T>
|
||||
struct is_callable<T,
|
||||
struct is_invocable<T,
|
||||
std::enable_if_t<!std::is_final<unqualified_t<T>>::value && std::is_class<unqualified_t<T>>::value
|
||||
&& std::is_destructible<unqualified_t<T>>::value>> {
|
||||
struct F {
|
||||
|
@ -301,7 +301,7 @@ namespace sol { namespace meta {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct is_callable<T,
|
||||
struct is_invocable<T,
|
||||
std::enable_if_t<!std::is_final<unqualified_t<T>>::value && std::is_class<unqualified_t<T>>::value
|
||||
&& !std::is_destructible<unqualified_t<T>>::value>> {
|
||||
struct F {
|
||||
|
@ -551,10 +551,10 @@ namespace sol { namespace meta {
|
|||
class supports_to_string_member : public meta::boolean<meta_detail::has_to_string_test<meta_detail::non_void_t<T>>::value> { };
|
||||
|
||||
template <typename T>
|
||||
using is_callable = boolean<meta_detail::is_callable<T>::value>;
|
||||
using is_invocable = boolean<meta_detail::is_invocable<T>::value>;
|
||||
|
||||
template <typename T>
|
||||
constexpr inline bool is_callable_v = is_callable<T>::value;
|
||||
constexpr inline bool is_invocable_v = is_invocable<T>::value;
|
||||
|
||||
template <typename T>
|
||||
struct has_begin_end : decltype(meta_detail::has_begin_end_impl::test<T>(0)) { };
|
||||
|
|
|
@ -898,7 +898,7 @@ namespace sol {
|
|||
struct is_callable : std::true_type { };
|
||||
|
||||
template <typename T>
|
||||
inline constexpr bool is_callable_v = is_callable_v<T>::value;
|
||||
inline constexpr bool is_callable_v = is_callable<T>::value;
|
||||
|
||||
namespace detail {
|
||||
template <typename T, typename = void>
|
||||
|
|
|
@ -154,25 +154,64 @@
|
|||
#define SOL_PLATFORM_ARM32_I_ SOL_OFF
|
||||
#define SOL_PLATFORM_ARM64_I_ SOL_OFF
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define SOL_PLATFORM_WINDOWS_I_ SOL_ON
|
||||
#if defined(SOL_PLATFORM_WINDOWS)
|
||||
#if (SOL_PLATFORM_WINDOWS != 0)
|
||||
#define SOL_PLATFORM_WINDOWS_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_PLATFORM_WINDOWS_I_ SOL_OFF
|
||||
#endif
|
||||
#elif defined(_WIN32)
|
||||
#define SOL_PLATFORM_WINDOWS_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_PLATFORM_WINDOWS_I_ SOL_OFF
|
||||
#define SOL_PLATFORM_WINDOWS_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#if defined(__APPLE__)
|
||||
#define SOL_PLATFORM_APPLE_I_ SOL_ON
|
||||
|
||||
#if defined(SOL_PLATFORM_CYGWIN)
|
||||
#if (SOL_PLATFORM_CYGWIN != 0)
|
||||
#define SOL_PLATFORM_CYGWIN_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_PLATFORM_CYGWIN_I_ SOL_ON
|
||||
#endif
|
||||
#elif defined(__CYGWIN__)
|
||||
#define SOL_PLATFORM_CYGWIN_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_PLATFORM_APPLE_I_ SOL_OFF
|
||||
#define SOL_PLATFORM_CYGWIN_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#if defined(__unix__)
|
||||
#define SOL_PLATFORM_UNIXLIKE_I_ SOL_ON
|
||||
|
||||
#if defined(SOL_PLATFORM_APPLE)
|
||||
#if (SOL_PLATFORM_APPLE != 0)
|
||||
#define SOL_PLATFORM_APPLE_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_PLATFORM_APPLE_I_ SOL_OFF
|
||||
#endif
|
||||
#elif defined(__APPLE__)
|
||||
#define SOL_PLATFORM_APPLE_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_PLATFORM_UNIXLIKE_I_ SOL_OFF
|
||||
#define SOL_PLATFORM_APPLE_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#if defined(__linux__)
|
||||
#define SOL_PLATFORM_LINUXLIKE_I_ SOL_ON
|
||||
|
||||
#if defined(SOL_PLATFORM_UNIX)
|
||||
#if (SOL_PLATFORM_UNIX != 0)
|
||||
#define SOL_PLATFORM_UNIXLIKE_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_PLATFORM_UNIXLIKE_I_ SOL_OFF
|
||||
#endif
|
||||
#elif defined(__unix__)
|
||||
#define SOL_PLATFORM_UNIXLIKE_I_ SOL_DEFAUKT_ON
|
||||
#else
|
||||
#define SOL_PLATFORM_LINUXLIKE_I_ SOL_OFF
|
||||
#define SOL_PLATFORM_UNIXLIKE_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
|
||||
#if defined(SOL_PLATFORM_LINUX)
|
||||
#if (SOL_PLATFORM_LINUX != 0)
|
||||
#define SOL_PLATFORM_LINUXLIKE_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_PLATFORM_LINUXLIKE_I_ SOL_OFF
|
||||
#endif
|
||||
#elif defined(__LINUX__)
|
||||
#define SOL_PLATFORM_LINUXLIKE_I_ SOL_DEFAUKT_ON
|
||||
#else
|
||||
#define SOL_PLATFORM_LINUXLIKE_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
|
||||
#define SOL_PLATFORM_APPLE_IPHONE_I_ SOL_OFF
|
||||
|
@ -782,112 +821,6 @@
|
|||
#define SOL_USER_M_ASSERT_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
|
||||
#if defined(SOL_HEADER_ONLY)
|
||||
#if (SOL_HEADER_ONLY != 0)
|
||||
#define SOL_HEADER_ONLY_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_HEADER_ONLY_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#define SOL_HEADER_ONLY_I_ SOL_DEFAULT_ON
|
||||
#endif
|
||||
|
||||
#if defined(SOL_BUILD)
|
||||
#if (SOL_BUILD != 0)
|
||||
#define SOL_BUILD_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_BUILD_I_ SOL_OFF
|
||||
#endif
|
||||
#elif SOL_IS_ON(SOL_HEADER_ONLY_I_)
|
||||
#define SOL_BUILD_I_ SOL_DEFAULT_OFF
|
||||
#else
|
||||
#define SOL_BUILD_I_ SOL_DEFAULT_ON
|
||||
#endif
|
||||
|
||||
#if defined(SOL_DLL)
|
||||
#if (SOL_DLL != 0)
|
||||
#define SOL_DLL_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_DLL_I_ SOL_OFF
|
||||
#endif
|
||||
#elif SOL_IS_ON(SOL_HEADER_ONLY_I_)
|
||||
#define SOL_DLL_I_ SOL_DEFAULT_OFF
|
||||
#else
|
||||
#define SOL_DLL_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
|
||||
#if defined(SOL_FUNC_DECL)
|
||||
#define SOL_FUNC_DECL_I_ SOL_FUNC_DECL
|
||||
#elif SOL_IS_ON(SOL_HEADER_ONLY_I_)
|
||||
#define SOL_FUNC_DECL_I_
|
||||
#elif SOL_IS_ON(SOL_DLL_I_)
|
||||
#if SOL_IS_ON(SOL_COMPILER_VCXX_I_)
|
||||
#if SOL_IS_ON(SOL_BUILD_I_)
|
||||
#define SOL_FUNC_DECL_I_ extern __declspec(dllexport)
|
||||
#else
|
||||
#define SOL_FUNC_DECL_I_ extern __declspec(dllimport)
|
||||
#endif
|
||||
#elif SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_)
|
||||
#define SOL_FUNC_DECL_I_ extern __attribute__((visibility("default")))
|
||||
#else
|
||||
#define SOL_FUNC_DECL_I_ extern
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SOL_FUNC_DEFN)
|
||||
#define SOL_FUNC_DEFN_I_ SOL_FUNC_DEFN
|
||||
#elif SOL_IS_ON(SOL_HEADER_ONLY_I_)
|
||||
#define SOL_FUNC_DEFN_I_ inline
|
||||
#elif SOL_IS_ON(SOL_DLL_I_)
|
||||
#if SOL_IS_ON(SOL_COMPILER_VCXX_I_)
|
||||
#if SOL_IS_ON(SOL_BUILD_I_)
|
||||
#define SOL_FUNC_DEFN_I_ __declspec(dllexport)
|
||||
#else
|
||||
#define SOL_FUNC_DEFN_I_ __declspec(dllimport)
|
||||
#endif
|
||||
#elif SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_)
|
||||
#define SOL_FUNC_DEFN_I_ __attribute__((visibility("default")))
|
||||
#else
|
||||
#define SOL_FUNC_DEFN_I_
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SOL_HIDDEN_FUNC_DECL)
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_ SOL_HIDDEN_FUNC_DECL
|
||||
#elif SOL_IS_ON(SOL_HEADER_ONLY_I_)
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_
|
||||
#elif SOL_IS_ON(SOL_DLL_I_)
|
||||
#if SOL_IS_ON(SOL_COMPILER_VCXX_I_)
|
||||
#if SOL_IS_ON(SOL_BUILD_I_)
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_ extern __declspec(dllexport)
|
||||
#else
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_ extern __declspec(dllimport)
|
||||
#endif
|
||||
#elif SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_)
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_ extern __attribute__((visibility("default")))
|
||||
#else
|
||||
#define SOL_HIDDEN_FUNC_DECL_I_ extern
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SOL_HIDDEN_FUNC_DEFN)
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_ SOL_HIDDEN_FUNC_DEFN
|
||||
#elif SOL_IS_ON(SOL_HEADER_ONLY_I_)
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_ inline
|
||||
#elif SOL_IS_ON(SOL_DLL_I_)
|
||||
#if SOL_IS_ON(SOL_COMPILER_VCXX_I_)
|
||||
#if SOL_IS_ON(SOL_BUILD_I_)
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_
|
||||
#else
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_
|
||||
#endif
|
||||
#elif SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_)
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_ __attribute__((visibility("hidden")))
|
||||
#else
|
||||
#define SOL_HIDDEN_FUNC_DEFN_I_
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sol/prologue.hpp>
|
||||
#include <sol/epilogue.hpp>
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ add_subdirectory(inclusion)
|
|||
add_subdirectory(enum)
|
||||
add_subdirectory(environment)
|
||||
add_subdirectory(exceptions)
|
||||
add_subdirectory(lua_lifetime)
|
||||
add_subdirectory(numerics)
|
||||
add_subdirectory(config_tests)
|
||||
add_subdirectory(regression_tests)
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
# # # # sol2
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2013-2021 Rapptz, ThePhD, and contributors
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
# this software and associated documentation files (the "Software"), to deal in
|
||||
# the Software without restriction, including without limitation the rights to
|
||||
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
# the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
# subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# # # # sol2 tests - enum
|
||||
|
||||
file(GLOB sources
|
||||
LIST_DIRECTORIES FALSE
|
||||
CONFIGURE_DEPENDS
|
||||
source/*.cpp)
|
||||
|
||||
sol2_create_basic_test(sol2.tests.enum sol2::sol2 ${sources})
|
||||
target_compile_definitions(sol2.tests.enum PRIVATE
|
||||
SOL_ALL_SAFETIES_ON=1)
|
|
@ -30,21 +30,21 @@ inline namespace sol2_tests_enum_read_only_iteration {
|
|||
}
|
||||
|
||||
|
||||
TEST_CASE("environments/sanboxing", "see if environments on functions are working properly") {
|
||||
TEST_CASE("enum/read-only-iteration", "make sure iteration for read only tables works properly") {
|
||||
sol::state lua;
|
||||
lua.open_libraries(sol::lib::base);
|
||||
constexpr bool ro = true;
|
||||
lua.new_enum<color, ro>("color", { { "red", color::red }, { "blue", color::blue } });
|
||||
auto script = R"lua(
|
||||
print( "start" )
|
||||
for k, v in pairs( color ) do
|
||||
print( tostring(k) .. ": " .. tostring(v) )
|
||||
end
|
||||
print( "end" )
|
||||
)lua";
|
||||
auto result = lua.safe_script(script, sol::script_pass_on_error);
|
||||
sol::optional<sol::error> maybe_error = result;
|
||||
REQUIRE(result.valid());
|
||||
REQUIRE(result.status() == sol::call_status::ok);
|
||||
REQUIRE_FALSE(maybe_error.has_value());
|
||||
#define TABLE_ENTRIES() "FIRST", 1, "SECOND", 2, "THIRD", 3, "NOT-FOURTH", 5
|
||||
lua.create_named_table("Check", TABLE_ENTRIES());
|
||||
lua.new_enum("Enum", TABLE_ENTRIES());
|
||||
#undef TABLE_ENTRIES
|
||||
|
||||
SECTION("without global next function") {
|
||||
sol::optional<sol::error> maybe_result = lua.safe_script("for k, v in pairs(Enum) do assert(Check[k] == v) end", sol::script_pass_on_error);
|
||||
REQUIRE_FALSE(maybe_result.has_value());
|
||||
}
|
||||
SECTION("with global next function") {
|
||||
lua.open_libraries(sol::lib::table);
|
||||
sol::optional<sol::error> maybe_result = lua.safe_script("for k, v in pairs(Enum) do assert(Check[k] == v) end", sol::script_pass_on_error);
|
||||
REQUIRE_FALSE(maybe_result.has_value());
|
||||
}
|
||||
}
|
||||
|
|
34
tests/lua_lifetime/CMakeLists.txt
Normal file
34
tests/lua_lifetime/CMakeLists.txt
Normal file
|
@ -0,0 +1,34 @@
|
|||
# # # # sol2
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2013-2021 Rapptz, ThePhD, and contributors
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
# this software and associated documentation files (the "Software"), to deal in
|
||||
# the Software without restriction, including without limitation the rights to
|
||||
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
# the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
# subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
# # # # sol2 tests - environment
|
||||
|
||||
file(GLOB sources
|
||||
LIST_DIRECTORIES FALSE
|
||||
CONFIGURE_DEPENDS
|
||||
source/*.cpp)
|
||||
|
||||
sol2_create_basic_test(sol2.tests.lua_lifetime sol2::sol2 ${sources})
|
||||
sol2_create_basic_test(sol2.tests.lua_lifetime.SOL_ALL_SAFETIES_ON sol2::sol2 ${sources})
|
||||
target_compile_definitions(sol2.tests.lua_lifetime.SOL_ALL_SAFETIES_ON
|
||||
PRIVATE
|
||||
SOL_ALL_SAFETIES_ON=1)
|
11
tests/lua_lifetime/source/main.cpp
Normal file
11
tests/lua_lifetime/source/main.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <sol/sol.hpp>
|
||||
|
||||
sol::function fn;
|
||||
|
||||
int main(int, char*[]) {
|
||||
sol::state lua;
|
||||
lua.open_libraries(sol::lib::base);
|
||||
fn = lua["print"];
|
||||
fn.abandon();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user