diff --git a/include/sol/sol.hpp b/include/sol/sol.hpp index bb0d21aa..16b146a2 100644 --- a/include/sol/sol.hpp +++ b/include/sol/sol.hpp @@ -23,12 +23,9 @@ #define SOL_HPP #if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) -#define SOL_INSIDE_UNREAL 1 -#endif // Unreal Engine 4 bullshit - -#if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL +#define SOL_INSIDE_UNREAL #ifdef check -#define SOL_INSIDE_UNREAL_REMOVED_CHECK 1 +#pragma push_macro("check") #undef check #endif #endif // Unreal Engine 4 Bullshit @@ -74,23 +71,9 @@ #pragma warning(push) #endif // g++ -#if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL -#if defined(SOL_INSIDE_UNREAL_REMOVED_CHECK) && SOL_INSIDE_UNREAL_REMOVED_CHECK -#if defined(DO_CHECK) && DO_CHECK -#define check(expr) \ - { \ - if (UNLIKELY(!(expr))) { \ - FDebug::LogAssertFailedMessage(#expr, __FILE__, __LINE__); \ - _DebugBreakAndPromptForRemote(); \ - FDebug::AssertFailed(#expr, __FILE__, __LINE__); \ - CA_ASSUME(false); \ - } \ - } -#else -#define check(expr) \ - { CA_ASSUME(expr); } -#endif -#endif +#if defined(SOL_INSIDE_UNREAL) +#undef check +#pragma pop_macro("check") #endif // Unreal Engine 4 Bullshit #endif // SOL_HPP diff --git a/include/sol/usertype_container.hpp b/include/sol/usertype_container.hpp index 84e406f9..c9357cb7 100644 --- a/include/sol/usertype_container.hpp +++ b/include/sol/usertype_container.hpp @@ -508,6 +508,10 @@ namespace sol { iter(T& source, iterator it) : source(source), it(std::move(it)), i(0) { } + + ~iter() { + + } }; static auto& get_src(lua_State* L) { @@ -1073,7 +1077,7 @@ namespace sol { auto& source = i.source; auto& it = i.it; if (it == deferred_uc::end(L, source)) { - return 0; + return stack::push(L, lua_nil); } int p; if (ip) { @@ -1095,7 +1099,7 @@ namespace sol { auto& it = i.it; next_K k = stack::unqualified_get(L, 2); if (it == deferred_uc::end(L, source)) { - return 0; + return stack::push(L, lua_nil); } int p; p = stack::push_reference(L, k + 1); diff --git a/single/include/sol/forward.hpp b/single/include/sol/forward.hpp index 1673b895..119afc0a 100644 --- a/single/include/sol/forward.hpp +++ b/single/include/sol/forward.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2019-02-14 07:36:40.809154 UTC -// This header was generated with sol v2.20.6 (revision ffe77cc) +// Generated 2019-02-14 09:52:13.841439 UTC +// This header was generated with sol v2.20.6 (revision b938e42) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP diff --git a/single/include/sol/sol.hpp b/single/include/sol/sol.hpp index 37c3b8c1..348baae6 100644 --- a/single/include/sol/sol.hpp +++ b/single/include/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2019-02-14 07:36:40.566598 UTC -// This header was generated with sol v2.20.6 (revision ffe77cc) +// Generated 2019-02-14 09:52:13.459443 UTC +// This header was generated with sol v2.20.6 (revision b938e42) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -33,12 +33,9 @@ #define SOL_HPP #if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) -#define SOL_INSIDE_UNREAL 1 -#endif // Unreal Engine 4 bullshit - -#if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL +#define SOL_INSIDE_UNREAL #ifdef check -#define SOL_INSIDE_UNREAL_REMOVED_CHECK 1 +#pragma push_macro("check") #undef check #endif #endif // Unreal Engine 4 Bullshit @@ -18758,6 +18755,10 @@ namespace sol { iter(T& source, iterator it) : source(source), it(std::move(it)), i(0) { } + + ~iter() { + + } }; static auto& get_src(lua_State* L) { @@ -19323,7 +19324,7 @@ namespace sol { auto& source = i.source; auto& it = i.it; if (it == deferred_uc::end(L, source)) { - return 0; + return stack::push(L, lua_nil); } int p; if (ip) { @@ -19345,7 +19346,7 @@ namespace sol { auto& it = i.it; next_K k = stack::unqualified_get(L, 2); if (it == deferred_uc::end(L, source)) { - return 0; + return stack::push(L, lua_nil); } int p; p = stack::push_reference(L, k + 1); @@ -24383,23 +24384,9 @@ namespace sol { #pragma warning(push) #endif // g++ -#if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL -#if defined(SOL_INSIDE_UNREAL_REMOVED_CHECK) && SOL_INSIDE_UNREAL_REMOVED_CHECK -#if defined(DO_CHECK) && DO_CHECK -#define check(expr) \ - { \ - if (UNLIKELY(!(expr))) { \ - FDebug::LogAssertFailedMessage(#expr, __FILE__, __LINE__); \ - _DebugBreakAndPromptForRemote(); \ - FDebug::AssertFailed(#expr, __FILE__, __LINE__); \ - CA_ASSUME(false); \ - } \ - } -#else -#define check(expr) \ - { CA_ASSUME(expr); } -#endif -#endif +#if defined(SOL_INSIDE_UNREAL) +#undef check +#pragma pop_macro("check") #endif // Unreal Engine 4 Bullshit #endif // SOL_HPP diff --git a/tests/runtime_tests/source/container_semantics.custom.cpp b/tests/runtime_tests/source/container_semantics.custom.cpp index 6126c77d..669ce91a 100644 --- a/tests/runtime_tests/source/container_semantics.custom.cpp +++ b/tests/runtime_tests/source/container_semantics.custom.cpp @@ -26,272 +26,11 @@ #include #include +#include +#include +#include +#include +#include +#include +#include #include // std::iota - - -struct my_object { -private: - std::vector mdata; - -public: - static const void* last_printed; - - my_object(int sz) : mdata() { - mdata.resize(sz); - std::iota(mdata.begin(), mdata.end(), 1); - } - - void operator()(std::size_t count, int value) { - for (; count > 0; --count) { - mdata.push_back(value); - } - } - -public: // Container requirements, as per the C++ standard - using value_type = int; - using reference = value_type&; - using const_reference = const value_type&; - using iterator = decltype(mdata)::iterator; - using const_iterator = decltype(mdata)::const_iterator; - using difference_type = decltype(mdata)::difference_type; - using size_type = decltype(mdata)::size_type; - - iterator begin() { - return iterator(mdata.begin()); - } - iterator end() { - return iterator(mdata.end()); - } - const_iterator begin() const { - return const_iterator(mdata.begin()); - } - const_iterator end() const { - return const_iterator(mdata.end()); - } - const_iterator cbegin() const { - return begin(); - } - const_iterator cend() const { - return end(); - } - size_type size() const noexcept { - return mdata.size(); - } - size_type max_size() const noexcept { - return mdata.max_size(); - } - void push_back(const value_type& v) { - mdata.push_back(v); - } - void insert(const_iterator where, const value_type& v) { - mdata.insert(where, v); - } - bool empty() const noexcept { - return mdata.empty(); - } - bool operator==(const my_object& right) const { - return mdata == right.mdata; - } - bool operator!=(const my_object& right) const noexcept { - return mdata != right.mdata; - } - - std::vector& data() { - return mdata; - } - - const std::vector& data() const { - return mdata; - } -}; - -const void* my_object::last_printed = nullptr; - -std::ostream& operator<<(std::ostream& ostr, const my_object& mo) { - my_object::last_printed = static_cast(&mo); - ostr << "{ "; - const auto& v = mo.data(); - if (v.empty()) { - ostr << "empty"; - } - else { - ostr << v[0]; - for (std::size_t i = 1; i < v.size(); ++i) { - ostr << ", " << v[i]; - } - } - ostr << " }"; - - return ostr; -} - -namespace sol { - template <> - struct is_container : std::false_type {}; -} // namespace sol - -TEST_CASE("containers/as_container reference", "test that we can force a container to be treated like one despite is_container being false_type") { - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("my_object", - sol::constructors(), - sol::call_constructor, - sol::constructors(), - "size", - &my_object::size, - "iterable", - [](my_object& mo) { return sol::as_container(mo); }); - -#if SOL_LUA_VERSION > 501 - auto result1 = lua.safe_script(R"( -mop = my_object.new(20) -for i, v in pairs(mop) do - assert(i == v) -end -print(mop) - )", - sol::script_pass_on_error); - REQUIRE(result1.valid()); - REQUIRE_NOTHROW([&]() { - my_object& mo = lua["mop"]; - REQUIRE((&mo == my_object::last_printed)); - }()); -#endif - auto result2 = lua.safe_script(R"( -mo = my_object(10) -c_mo = mo -c_iterable = mo:iterable() -)", - sol::script_pass_on_error); - REQUIRE(result2.valid()); - - REQUIRE_NOTHROW([&]() { - my_object& mo = lua["c_mo"]; - my_object& mo_iterable = lua["c_iterable"]; - REQUIRE(&mo == &mo_iterable); - REQUIRE(mo == mo_iterable); - }()); - - auto result3 = lua.safe_script(R"( -s1 = c_mo:size() -s1_len = #c_mo -s1_iterable = c_iterable:size() -s1_iterable_len = #c_iterable -)"); - REQUIRE(result3.valid()); - - REQUIRE_NOTHROW([&]() { - std::size_t s1 = lua["s1"]; - std::size_t s1_len = lua["s1_len"]; - std::size_t s1_iterable = lua["s1_iterable"]; - std::size_t s1_iterable_len = lua["s1_iterable_len"]; - REQUIRE(s1 == 10); - REQUIRE(s1 == s1_len); - REQUIRE(s1 == s1_iterable_len); - REQUIRE(s1_iterable == s1_iterable_len); - }()); - - auto result4 = lua.safe_script(R"( -for i=1,#c_mo do - v_iterable = c_iterable[i] - assert(v_iterable == i) -end -)", - sol::script_pass_on_error); - REQUIRE(result4.valid()); - - auto result5 = lua.safe_script(R"( -mo(5, 20) -c_iterable:insert(1, 100) -v1 = c_iterable[1] -s2 = c_mo:size() -s2_len = #c_mo -s2_iterable = c_iterable:size() -s2_iterable_len = #c_iterable -print(mo) - )", - sol::script_pass_on_error); - REQUIRE(result5.valid()); - - int v1 = lua["v1"]; - std::size_t s2 = lua["s2"]; - std::size_t s2_len = lua["s2_len"]; - std::size_t s2_iterable = lua["s2_iterable"]; - std::size_t s2_iterable_len = lua["s2_iterable_len"]; - REQUIRE(v1 == 100); - REQUIRE(s2 == 16); - REQUIRE(s2 == s2_len); - REQUIRE(s2 == s2_iterable_len); - REQUIRE(s2_iterable == s2_iterable_len); - - my_object& mo = lua["mo"]; - REQUIRE(&mo == my_object::last_printed); -} - -TEST_CASE("containers/as_container", "test that we can force a container to be treated like one despite the trait being false using the proper marker") { - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.set_function("f", [](int v) { return sol::as_container(my_object(v)); }); - -#if SOL_LUA_VERSION > 501 - auto result1 = lua.safe_script(R"( -mop = f(20) -for i, v in pairs(mop) do - assert(i == v) -end - )"); - REQUIRE(result1.valid()); -#endif - auto result2 = lua.safe_script(R"( -mo = f(10) -c_iterable = mo -)"); - REQUIRE(result2.valid()); - - { - my_object& mo = lua["mo"]; - my_object& mo_iterable = lua["c_iterable"]; - REQUIRE(&mo == &mo_iterable); - REQUIRE(mo == mo_iterable); - } - - auto result3 = lua.safe_script(R"( -s1_iterable = c_iterable:size() -s1_iterable_len = #c_iterable -)"); - REQUIRE(result3.valid()); - - { - std::size_t s1_iterable = lua["s1_iterable"]; - std::size_t s1_iterable_len = lua["s1_iterable_len"]; - REQUIRE(s1_iterable == 10); - REQUIRE(s1_iterable == s1_iterable_len); - } - - auto result4 = lua.safe_script(R"( -for i=1,#c_iterable do - v_iterable = c_iterable[i] - assert(v_iterable == i) -end -)"); - REQUIRE(result4.valid()); - - auto result5 = lua.safe_script(R"( -c_iterable:insert(1, 100) -v1 = c_iterable:get(1) -s2_iterable = c_iterable:size() -s2_iterable_len = #c_iterable - )"); - REQUIRE(result5.valid()); - - { - int v1 = lua["v1"]; - std::size_t s2_iterable = lua["s2_iterable"]; - std::size_t s2_iterable_len = lua["s2_iterable_len"]; - REQUIRE(v1 == 100); - REQUIRE(s2_iterable_len == 11); - REQUIRE(s2_iterable == s2_iterable_len); - } -}