From 79b04acd66b1675d96e54f8c61f07575c5e4111e Mon Sep 17 00:00:00 2001 From: ThePhD Date: Fri, 19 Sep 2014 11:08:44 -0400 Subject: [PATCH] Proper deprecation to alert users to API name changes. --- sol/deprecate.hpp | 11 ++++++++++- sol/state.hpp | 20 ++++++++++++++++++++ sol/table.hpp | 12 +++++++++++- sol/types.hpp | 2 +- sol/usertype.hpp | 16 ++++++++++++++++ 5 files changed, 58 insertions(+), 3 deletions(-) diff --git a/sol/deprecate.hpp b/sol/deprecate.hpp index f00a6e12..498e4807 100644 --- a/sol/deprecate.hpp +++ b/sol/deprecate.hpp @@ -32,4 +32,13 @@ #endif // compilers #endif // SOL_DEPRECATED -#endif // SOL_DEPRECATE_HPP +namespace sol { +namespace detail { + template + struct SOL_DEPRECATED deprecate_type { + using type = T; + }; +} // detail +} // sol + +#endif // SOL_DEPRECATE_HPP diff --git a/sol/state.hpp b/sol/state.hpp index 77a11ed8..8417f717 100644 --- a/sol/state.hpp +++ b/sol/state.hpp @@ -147,6 +147,26 @@ public: return *this; } + template + SOL_DEPRECATED table& set_userdata(usertype& user) { + return set_usertype(user); + } + + template + SOL_DEPRECATED table& set_userdata(Key&& key, usertype& user) { + return set_usertype(std::forward(key), user); + } + + template + SOL_DEPRECATED state& new_userdata(const std::string& name, Args&&... args) { + return new_usertype(name, std::forward(args)...); + } + + template + SOL_DEPRECATED state& new_userdata(const std::string& name, constructors ctor, Args&&... args) { + return new_usertype(name, std::move(ctor), std::forward(args)...); + } + template state& set_usertype(usertype& user) { return set_usertype(usertype_traits::name, user); diff --git a/sol/table.hpp b/sol/table.hpp index 04290db9..df2aa70a 100644 --- a/sol/table.hpp +++ b/sol/table.hpp @@ -83,9 +83,19 @@ public: return *this; } + template + SOL_DEPRECATED table& set_userdata(usertype& user) { + return set_usertype(user); + } + + template + SOL_DEPRECATED table& set_userdata(Key&& key, usertype& user) { + return set_usertype(std::forward(key), user); + } + template table& set_usertype(usertype& user) { - return set_userdata(usertype_traits::name, user); + return set_usertype(usertype_traits::name, user); } template diff --git a/sol/types.hpp b/sol/types.hpp index a72f09ce..31439924 100644 --- a/sol/types.hpp +++ b/sol/types.hpp @@ -90,7 +90,7 @@ inline std::string type_name(lua_State*L, type t) { } template -class userdata; +class usertype; class table; class function; class object; diff --git a/sol/usertype.hpp b/sol/usertype.hpp index 4150dda8..75468168 100644 --- a/sol/usertype.hpp +++ b/sol/usertype.hpp @@ -26,6 +26,7 @@ #include "function_types.hpp" #include "usertype_traits.hpp" #include "default_construct.hpp" +#include "deprecate.hpp" #include #include #include @@ -315,6 +316,18 @@ public: template usertype(Args&&... args): usertype(default_constructor, std::forward(args)...) {} + template + SOL_DEPRECATED usertype(std::string, Args&&... args): usertype(default_constructor, std::forward(args)...) {} + + template + SOL_DEPRECATED usertype(const char*, Args&&... args): usertype(default_constructor, std::forward(args)...) {} + + template + SOL_DEPRECATED usertype(std::string, constructors c, Args&&... args) : usertype(std::move(c), std::forward(args)...) {} + + template + SOL_DEPRECATED usertype(const char*, constructors c, Args&&... args) : usertype(std::move(c), std::forward(args)...) {} + template usertype(constructors, Args&&... args) { functionnames.reserve(sizeof...(args) + 2); @@ -392,6 +405,9 @@ private: } }; +template +using userdata = typename detail::deprecate_type>::type; + namespace stack { template struct pusher> {