Proper deprecation to alert users to API name changes.

This commit is contained in:
ThePhD 2014-09-19 11:08:44 -04:00
parent a767859e24
commit 79b04acd66
5 changed files with 58 additions and 3 deletions

View File

@ -32,4 +32,13 @@
#endif // compilers #endif // compilers
#endif // SOL_DEPRECATED #endif // SOL_DEPRECATED
#endif // SOL_DEPRECATE_HPP namespace sol {
namespace detail {
template <typename T>
struct SOL_DEPRECATED deprecate_type {
using type = T;
};
} // detail
} // sol
#endif // SOL_DEPRECATE_HPP

View File

@ -147,6 +147,26 @@ public:
return *this; return *this;
} }
template<typename T>
SOL_DEPRECATED table& set_userdata(usertype<T>& user) {
return set_usertype(user);
}
template<typename Key, typename T>
SOL_DEPRECATED table& set_userdata(Key&& key, usertype<T>& user) {
return set_usertype(std::forward<Key>(key), user);
}
template<typename Class, typename... CTor, typename... Args>
SOL_DEPRECATED state& new_userdata(const std::string& name, Args&&... args) {
return new_usertype<Class>(name, std::forward<Args>(args)...);
}
template<typename Class, typename... CArgs, typename... Args>
SOL_DEPRECATED state& new_userdata(const std::string& name, constructors<CArgs...> ctor, Args&&... args) {
return new_usertype(name, std::move(ctor), std::forward<Args>(args)...);
}
template<typename T> template<typename T>
state& set_usertype(usertype<T>& user) { state& set_usertype(usertype<T>& user) {
return set_usertype(usertype_traits<T>::name, user); return set_usertype(usertype_traits<T>::name, user);

View File

@ -83,9 +83,19 @@ public:
return *this; return *this;
} }
template<typename T>
SOL_DEPRECATED table& set_userdata(usertype<T>& user) {
return set_usertype(user);
}
template<typename Key, typename T>
SOL_DEPRECATED table& set_userdata(Key&& key, usertype<T>& user) {
return set_usertype(std::forward<Key>(key), user);
}
template<typename T> template<typename T>
table& set_usertype(usertype<T>& user) { table& set_usertype(usertype<T>& user) {
return set_userdata(usertype_traits<T>::name, user); return set_usertype(usertype_traits<T>::name, user);
} }
template<typename Key, typename T> template<typename Key, typename T>

View File

@ -90,7 +90,7 @@ inline std::string type_name(lua_State*L, type t) {
} }
template<typename T> template<typename T>
class userdata; class usertype;
class table; class table;
class function; class function;
class object; class object;

View File

@ -26,6 +26,7 @@
#include "function_types.hpp" #include "function_types.hpp"
#include "usertype_traits.hpp" #include "usertype_traits.hpp"
#include "default_construct.hpp" #include "default_construct.hpp"
#include "deprecate.hpp"
#include <vector> #include <vector>
#include <array> #include <array>
#include <algorithm> #include <algorithm>
@ -315,6 +316,18 @@ public:
template<typename... Args> template<typename... Args>
usertype(Args&&... args): usertype(default_constructor, std::forward<Args>(args)...) {} usertype(Args&&... args): usertype(default_constructor, std::forward<Args>(args)...) {}
template<typename... Args>
SOL_DEPRECATED usertype(std::string, Args&&... args): usertype(default_constructor, std::forward<Args>(args)...) {}
template<typename... Args>
SOL_DEPRECATED usertype(const char*, Args&&... args): usertype(default_constructor, std::forward<Args>(args)...) {}
template<typename... Args, typename... CArgs>
SOL_DEPRECATED usertype(std::string, constructors<CArgs...> c, Args&&... args) : usertype(std::move(c), std::forward<Args>(args)...) {}
template<typename... Args, typename... CArgs>
SOL_DEPRECATED usertype(const char*, constructors<CArgs...> c, Args&&... args) : usertype(std::move(c), std::forward<Args>(args)...) {}
template<typename... Args, typename... CArgs> template<typename... Args, typename... CArgs>
usertype(constructors<CArgs...>, Args&&... args) { usertype(constructors<CArgs...>, Args&&... args) {
functionnames.reserve(sizeof...(args) + 2); functionnames.reserve(sizeof...(args) + 2);
@ -392,6 +405,9 @@ private:
} }
}; };
template <typename T>
using userdata = typename detail::deprecate_type<usertype<T>>::type;
namespace stack { namespace stack {
template<typename T> template<typename T>
struct pusher<usertype<T>> { struct pusher<usertype<T>> {