From a86e9ee62d2c480b8f038053bbe8766edd50c4c6 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Thu, 7 Dec 2017 09:04:19 -0500 Subject: [PATCH] update examples and fix error_result returns --- .../quick_n_dirty/running_lua_code.cpp | 4 + .../running_lua_code_low_level.cpp | 5 + single/sol/sol.hpp | 6 +- sol/container_traits.hpp | 2 +- tests/test_containers.cpp | 196 +++++++++--------- 5 files changed, 111 insertions(+), 102 deletions(-) diff --git a/examples/tutorials/quick_n_dirty/running_lua_code.cpp b/examples/tutorials/quick_n_dirty/running_lua_code.cpp index d6ac35ff..894c8007 100644 --- a/examples/tutorials/quick_n_dirty/running_lua_code.cpp +++ b/examples/tutorials/quick_n_dirty/running_lua_code.cpp @@ -40,5 +40,9 @@ int main(int, char*[]) { std::cout << std::endl; + { + std::remove("a_lua_script.lua"); + } + return 0; } diff --git a/examples/tutorials/quick_n_dirty/running_lua_code_low_level.cpp b/examples/tutorials/quick_n_dirty/running_lua_code_low_level.cpp index b871772a..0155fd18 100644 --- a/examples/tutorials/quick_n_dirty/running_lua_code_low_level.cpp +++ b/examples/tutorials/quick_n_dirty/running_lua_code_low_level.cpp @@ -3,6 +3,7 @@ #include #include +#include #include int main(int, char*[]) { @@ -40,5 +41,9 @@ int main(int, char*[]) { std::cout << std::endl; + { + std::remove("a_lua_script.lua"); + } + return 0; } diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 9189bdbb..925d7fad 100644 --- a/single/sol/sol.hpp +++ b/single/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 2017-12-07 13:23:41.409999 UTC -// This header was generated with sol v2.18.7 (revision e17c0a1) +// Generated 2017-12-07 14:04:12.736591 UTC +// This header was generated with sol v2.18.7 (revision 7193115) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -15258,7 +15258,7 @@ namespace sol { return set_writable(is_writable(), L, self, it, std::move(value)); } - static void set_comparative(std::true_type, lua_State* L, T& self, stack_object okey, stack_object value) { + static error_result set_comparative(std::true_type, lua_State* L, T& self, stack_object okey, stack_object value) { decltype(auto) key = okey.as(); if (!is_writable::value) { return error_result("cannot perform a 'set': '%s's iterator reference is not writable (non-copy-assignable or const)", detail::demangle().data()); diff --git a/sol/container_traits.hpp b/sol/container_traits.hpp index 51ebe46a..5bb669e6 100644 --- a/sol/container_traits.hpp +++ b/sol/container_traits.hpp @@ -668,7 +668,7 @@ namespace sol { return set_writable(is_writable(), L, self, it, std::move(value)); } - static void set_comparative(std::true_type, lua_State* L, T& self, stack_object okey, stack_object value) { + static error_result set_comparative(std::true_type, lua_State* L, T& self, stack_object okey, stack_object value) { decltype(auto) key = okey.as(); if (!is_writable::value) { return error_result("cannot perform a 'set': '%s's iterator reference is not writable (non-copy-assignable or const)", detail::demangle().data()); diff --git a/tests/test_containers.cpp b/tests/test_containers.cpp index 10ce965d..5330f1e5 100644 --- a/tests/test_containers.cpp +++ b/tests/test_containers.cpp @@ -15,6 +15,104 @@ #include #include +class int_shim { +public: + int_shim() = default; + + int_shim(int x) + : x_(x) { + } + + int val() const { + return x_; + } + +private: + int x_ = -1; +}; + +class input_it { +public: + typedef std::input_iterator_tag iterator_category; + typedef int_shim value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef std::ptrdiff_t difference_type; + + input_it() = default; + + input_it(int n, int m) + : n_(n), m_(m), value_(n_) { + assert(n_ >= 0); + assert(m_ >= 0); + assert(n_ <= m_); + + if (!n_ && !m_) { + n_ = -1; + m_ = -1; + value_ = -1; + } + } + + const int_shim& operator*() const { + return value_; + } + + const int_shim* operator->() const { + return &value_; + } + + input_it& operator++() { + assert(n_ >= 0); + assert(m_ >= 0); + if (n_ == m_ - 1) { + n_ = m_ = -1; + } + else { + ++n_; + } + value_ = n_; + return *this; + } + + bool operator==(const input_it& i) const { + return n_ == i.n_ && m_ == i.m_; + } + + bool operator!=(const input_it& i) const { + return !(*this == i); + } + +private: + int n_ = -1; + int m_ = -1; + int_shim value_; +}; + +class not_really_a_container { +public: + using value_type = int_shim; + using iterator = input_it; + using const_iterator = input_it; + + const_iterator begin() const { + return iterator(0, 100); + } + + const_iterator end() const { + return iterator(); + } + + value_type gcc_warning_block() { + return int_shim(); + } + + std::size_t size() const { + return 100; + } +}; + auto test_table_return_one() { return sol::as_table(std::vector{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); } @@ -821,104 +919,6 @@ TEST_CASE("containers/non_copyable", "make sure non-copyable types in containers } TEST_CASE("containers/input iterators", "test shitty input iterators that are all kinds of B L E H") { - class int_shim { - public: - int_shim() = default; - - int_shim(int x) - : x_(x) { - } - - int val() const { - return x_; - } - - private: - int x_ = -1; - }; - - class input_it { - public: - typedef std::input_iterator_tag iterator_category; - typedef int_shim value_type; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef value_type* pointer; - typedef std::ptrdiff_t difference_type; - - input_it() = default; - - input_it(int n, int m) - : n_(n), m_(m), value_(n_) { - assert(n_ >= 0); - assert(m_ >= 0); - assert(n_ <= m_); - - if (!n_ && !m_) { - n_ = -1; - m_ = -1; - value_ = -1; - } - } - - const int_shim& operator*() const { - return value_; - } - - const int_shim* operator->() const { - return &value_; - } - - input_it& operator++() { - assert(n_ >= 0); - assert(m_ >= 0); - if (n_ == m_ - 1) { - n_ = m_ = -1; - } - else { - ++n_; - } - value_ = n_; - return *this; - } - - bool operator==(const input_it& i) const { - return n_ == i.n_ && m_ == i.m_; - } - - bool operator!=(const input_it& i) const { - return !(*this == i); - } - - private: - int n_ = -1; - int m_ = -1; - int_shim value_; - }; - - class not_really_a_container { - public: - using value_type = int_shim; - using iterator = input_it; - using const_iterator = input_it; - - const_iterator begin() const { - return iterator(0, 100); - } - - const_iterator end() const { - return iterator(); - } - - value_type gcc_warning_block() { - return int_shim(); - } - - std::size_t size() const { - return 100; - } - }; - sol::state lua; lua.open_libraries(sol::lib::base, sol::lib::package); lua.new_usertype("int_shim",