From 908074e6964676899169209fe19b14ac8b84afdc Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 2 Oct 2019 02:37:36 -0400 Subject: [PATCH] wew lad --- docs/source/errors.rst | 11 +++++- docs/source/mentions.rst | 4 +- docs/source/performance.rst | 4 +- include/sol/function.hpp | 2 +- include/sol/optional_implementation.hpp | 19 +++++---- include/sol/unique_usertype_traits.hpp | 6 +-- include/sol/usertype_container.hpp | 18 +++++++-- include/sol/usertype_storage.hpp | 1 + single/include/sol/forward.hpp | 6 +-- single/include/sol/sol.hpp | 51 ++++++++++++++++--------- 10 files changed, 81 insertions(+), 41 deletions(-) diff --git a/docs/source/errors.rst b/docs/source/errors.rst index 9d476bc1..e05f1736 100644 --- a/docs/source/errors.rst +++ b/docs/source/errors.rst @@ -47,7 +47,16 @@ Typical of Visual Studio, the compiler will complain that it is out of heap spac -This should use the 64-bit tools by default, and increase your maximum heap space to whatever a 64-bit windows machine can handle. If you do not have more than 4 GB of RAM, or you still encounter issues, you should look into using ``create_simple_usertype`` and adding functions 1 by 1 using ``.set( ... )``, as shown in `the simple usertype example here`_. +This should use the 64-bit tools by default, and increase your maximum heap space to whatever a 64-bit windows machine can handle. If you do not have more than 4 GB of RAM, or you still encounter issues, you should look into breaking up your usertype across C++ files. Also, it is imperative to not put all the functions inside single calls to the `new_usertype(...)` function directly: instead, use `my_usertype["func"] = func;` like so: + +.. code-block:: cpp + + auto my_usertype = lua.new_usertype("my_class"); + my_usertype["talkin"] = &about; + my_usertype["this"] = &my_class::that; + my_usertype["and_the"] = sol::property(&my_class::third); + + Linker Errors diff --git a/docs/source/mentions.rst b/docs/source/mentions.rst index f4d8bcdd..22440ec1 100644 --- a/docs/source/mentions.rst +++ b/docs/source/mentions.rst @@ -23,7 +23,7 @@ Okay, so the features don't convince you, the documentation doesn't convince you | |before| | |after| | +----------+---------+ -* In `Perforce`_ +* In `Perforce`_ (later versions of the code using sol2 more directly can be requested by e-mailing support@perforce.com !) * In `High Performance Computing research`_ - `Published research, too!`_ * The `Multiple Arcade Machine Emulator (MAME)`_ project switched from using LuaBridge to sol3! @@ -42,7 +42,7 @@ Okay, so the features don't convince you, the documentation doesn't convince you - Elias Daler: `"sol3 saved my life."`_ - Racod's Lair: `"from outdated LuaBridge to superior #sol3"`_ * (Reddit) Posts on reddit about it! - - `sol3's initial reddit release`_ + - `sol2's initial reddit release`_ - `Benchmarking Discussing`_ * Somehow landed on a Torque3D thread... - http://forums.torque3d.org/viewtopic.php?f=32&t=629&p=5246&sid=8e759990ab1ce38a48e896fc9fd62653#p5241 diff --git a/docs/source/performance.rst b/docs/source/performance.rst index ee1ab16c..61c152db 100644 --- a/docs/source/performance.rst +++ b/docs/source/performance.rst @@ -13,4 +13,6 @@ As shown by the :doc:`benchmarks`, sol is very performant with its a * Member variables can sometimes cost an extra lookup to occur within the Lua system (as mentioned :doc:`bottom of the usertype page`); until we find out a safe way around this, member variables will always incur that extra lookup cost -That's it as far as different performance options are avilable to make sol run faster. Again, please make sure to invoke these only when you know sol is the bottleneck. If you find some form of the performance unacceptable to you, also feel free to open an issue at the github. +Working with things that are already on the stack can also boost performance. Last time regular, call overhead was measured, it was around 5-11 nanoseconds for a single C++ call on a recent (2015) machine. The range is for how slim you make the call, what kind of arguments, et cetera. + +If you find some form of the performance unacceptable to you, also feel free to open an issue at the github. diff --git a/include/sol/function.hpp b/include/sol/function.hpp index 84dcaf67..bbbfc5ef 100644 --- a/include/sol/function.hpp +++ b/include/sol/function.hpp @@ -114,7 +114,7 @@ namespace sol { template static std::function get_std_func(types, lua_State* L, int index) { detail::std_shim fx(unsafe_function(L, index)); - return std::move(fx); + return fx; } static std::function get(lua_State* L, int index, record& tracking) { diff --git a/include/sol/optional_implementation.hpp b/include/sol/optional_implementation.hpp index 0d9abc0e..ebfe19f4 100644 --- a/include/sol/optional_implementation.hpp +++ b/include/sol/optional_implementation.hpp @@ -109,7 +109,7 @@ namespace sol { namespace detail { /// \exclude #define SOL_TL_OPTIONAL_11_CONSTEXPR #else -/// \exclude + /// \exclude #define SOL_TL_OPTIONAL_11_CONSTEXPR constexpr #endif @@ -448,10 +448,12 @@ namespace sol { // This specialization is for when T is not trivially copy constructible template struct optional_copy_base : optional_operations_base { - using optional_operations_base::optional_operations_base; + using base_t = optional_operations_base; + + using base_t::base_t; optional_copy_base() = default; - optional_copy_base(const optional_copy_base& rhs) { + optional_copy_base(const optional_copy_base& rhs) : base_t() { if (rhs.has_value()) { this->construct(rhs.get()); } @@ -500,7 +502,8 @@ namespace sol { // This class manages conditionally having a trivial copy assignment operator template + bool = SOL_TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE(T) && SOL_TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) + && SOL_TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE(T)> struct optional_copy_assign_base : optional_move_base { using optional_move_base::optional_move_base; }; @@ -1124,8 +1127,8 @@ namespace sol { } #if 0 // SOL_MODIFICATION - /// Constructs the stored value with `u`. - /// \synopsis template constexpr optional(U &&u); + /// Constructs the stored value with `u`. + /// \synopsis template constexpr optional(U &&u); template ::value>* = nullptr, detail::enable_forward_value* = nullptr> constexpr optional(U&& u) : base(in_place, std::forward(u)) { } @@ -2259,12 +2262,12 @@ namespace sol { namespace std { // TODO SFINAE template - struct hash< ::sol::optional > { + struct hash<::sol::optional> { ::std::size_t operator()(const ::sol::optional& o) const { if (!o.has_value()) return 0; - return ::std::hash< ::sol::detail::remove_const_t>()(*o); + return ::std::hash<::sol::detail::remove_const_t>()(*o); } }; } // namespace std diff --git a/include/sol/unique_usertype_traits.hpp b/include/sol/unique_usertype_traits.hpp index fbd3e179..75b248dd 100644 --- a/include/sol/unique_usertype_traits.hpp +++ b/include/sol/unique_usertype_traits.hpp @@ -95,8 +95,8 @@ namespace sol { inline constexpr bool is_unique_usertype_v = is_unique_usertype::value; namespace detail { - template - using is_base_rebindable_test = decltype(T::rebind_base); + template + using is_base_rebindable_test = typename T::template rebind_base; } template @@ -106,7 +106,7 @@ namespace sol { inline constexpr bool is_base_rebindable_v = is_base_rebindable::value; namespace detail { - template + template struct is_base_rebindable_non_void_sfinae : std::false_type {}; template diff --git a/include/sol/usertype_container.hpp b/include/sol/usertype_container.hpp index ce4a1bba..b05494eb 100644 --- a/include/sol/usertype_container.hpp +++ b/include/sol/usertype_container.hpp @@ -1258,13 +1258,23 @@ namespace sol { } static iterator begin(lua_State*, T& self) { - using std::begin; - return begin(self); + if constexpr (meta::has_begin_end_v) { + return self.begin(); + } + else { + using std::begin; + return begin(self); + } } static iterator end(lua_State*, T& self) { - using std::end; - return end(self); + if constexpr (meta::has_begin_end_v) { + return self.end(); + } + else { + using std::end; + return end(self); + } } static int size(lua_State* L) { diff --git a/include/sol/usertype_storage.hpp b/include/sol/usertype_storage.hpp index 690f65f9..e646966b 100644 --- a/include/sol/usertype_storage.hpp +++ b/include/sol/usertype_storage.hpp @@ -658,6 +658,7 @@ namespace sol { namespace u_detail { this->named_index_table.pop(); } else if constexpr (std::is_same_v) { + (void)key; this->update_bases(L, std::forward(value)); } else if constexpr ((meta::is_string_like_or_constructible::value || std::is_same_v)) { diff --git a/single/include/sol/forward.hpp b/single/include/sol/forward.hpp index 3718ffec..4089243b 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-09-15 04:36:38.687873 UTC -// This header was generated with sol v3.0.3 (revision b2c22ea) +// Generated 2019-10-02 06:37:27.657219 UTC +// This header was generated with sol v3.0.3 (revision 3768063) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP @@ -34,7 +34,7 @@ // beginning of sol/feature_test.hpp -#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)))) +#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)))) #ifndef SOL_CXX17_FEATURES #define SOL_CXX17_FEATURES 1 #endif // C++17 features macro diff --git a/single/include/sol/sol.hpp b/single/include/sol/sol.hpp index 9f986238..7373a98c 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-09-15 04:36:35.549872 UTC -// This header was generated with sol v3.0.3 (revision b2c22ea) +// Generated 2019-10-02 06:37:26.989637 UTC +// This header was generated with sol v3.0.3 (revision 3768063) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -60,7 +60,7 @@ // beginning of sol/feature_test.hpp -#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)))) +#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)))) #ifndef SOL_CXX17_FEATURES #define SOL_CXX17_FEATURES 1 #endif // C++17 features macro @@ -3752,6 +3752,7 @@ namespace sol { namespace detail { #if (__cplusplus == 201103L || defined(SOL_TL_OPTIONAL_MSVC2015) || defined(SOL_TL_OPTIONAL_GCC49)) #define SOL_TL_OPTIONAL_11_CONSTEXPR #else + /// \exclude #define SOL_TL_OPTIONAL_11_CONSTEXPR constexpr #endif @@ -4087,10 +4088,12 @@ namespace sol { // This specialization is for when T is not trivially copy constructible template struct optional_copy_base : optional_operations_base { - using optional_operations_base::optional_operations_base; + using base_t = optional_operations_base; + + using base_t::base_t; optional_copy_base() = default; - optional_copy_base(const optional_copy_base& rhs) { + optional_copy_base(const optional_copy_base& rhs) : base_t() { if (rhs.has_value()) { this->construct(rhs.get()); } @@ -4134,7 +4137,8 @@ namespace sol { // This class manages conditionally having a trivial copy assignment operator template + bool = SOL_TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE(T) && SOL_TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) + && SOL_TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE(T)> struct optional_copy_assign_base : optional_move_base { using optional_move_base::optional_move_base; }; @@ -4749,8 +4753,8 @@ namespace sol { } #if 0 // SOL_MODIFICATION - /// Constructs the stored value with `u`. - /// \synopsis template constexpr optional(U &&u); + /// Constructs the stored value with `u`. + /// \synopsis template constexpr optional(U &&u); template ::value>* = nullptr, detail::enable_forward_value* = nullptr> constexpr optional(U&& u) : base(in_place, std::forward(u)) { } @@ -5880,12 +5884,12 @@ namespace sol { namespace std { // TODO SFINAE template - struct hash< ::sol::optional > { + struct hash<::sol::optional> { ::std::size_t operator()(const ::sol::optional& o) const { if (!o.has_value()) return 0; - return ::std::hash< ::sol::detail::remove_const_t>()(*o); + return ::std::hash<::sol::detail::remove_const_t>()(*o); } }; } // namespace std @@ -8064,8 +8068,8 @@ namespace sol { inline constexpr bool is_unique_usertype_v = is_unique_usertype::value; namespace detail { - template - using is_base_rebindable_test = decltype(T::rebind_base); + template + using is_base_rebindable_test = typename T::template rebind_base; } template @@ -8075,7 +8079,7 @@ namespace sol { inline constexpr bool is_base_rebindable_v = is_base_rebindable::value; namespace detail { - template + template struct is_base_rebindable_non_void_sfinae : std::false_type {}; template @@ -18973,7 +18977,7 @@ namespace sol { template static std::function get_std_func(types, lua_State* L, int index) { detail::std_shim fx(unsafe_function(L, index)); - return std::move(fx); + return fx; } static std::function get(lua_State* L, int index, record& tracking) { @@ -20285,13 +20289,23 @@ namespace sol { } static iterator begin(lua_State*, T& self) { - using std::begin; - return begin(self); + if constexpr (meta::has_begin_end_v) { + return self.begin(); + } + else { + using std::begin; + return begin(self); + } } static iterator end(lua_State*, T& self) { - using std::end; - return end(self); + if constexpr (meta::has_begin_end_v) { + return self.end(); + } + else { + using std::end; + return end(self); + } } static int size(lua_State* L) { @@ -21723,6 +21737,7 @@ namespace sol { namespace u_detail { this->named_index_table.pop(); } else if constexpr (std::is_same_v) { + (void)key; this->update_bases(L, std::forward(value)); } else if constexpr ((meta::is_string_like_or_constructible::value || std::is_same_v)) {