mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Add support for setting functions with operator[]
This commit is contained in:
parent
7cc8c93289
commit
af0097fb7f
|
@ -217,10 +217,15 @@ private:
|
|||
proxy(table& t, T& key): t(t), key(key) {}
|
||||
|
||||
template<typename U>
|
||||
void operator=(U&& other) {
|
||||
DisableIf<Function<Unqualified<U>>> operator=(U&& other) {
|
||||
t.set(key, std::forward<U>(other));
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
EnableIf<Function<Unqualified<U>>> operator=(U&& other) {
|
||||
t.set_function(key, std::forward<U>(other));
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
operator U() const {
|
||||
return t.get<U>(key);
|
||||
|
|
|
@ -34,11 +34,14 @@ using DisableIf = typename std::enable_if<!T::value, R>::type;
|
|||
template<typename T>
|
||||
using Unqualified = typename std::remove_reference<typename std::remove_cv<T>::type>::type;
|
||||
|
||||
template<typename T>
|
||||
using Decay = typename std::decay<T>::type;
|
||||
|
||||
namespace detail {
|
||||
// code borrowed from Gears
|
||||
// https://github.com/Rapptz/Gears/
|
||||
template<typename T, typename = void>
|
||||
struct is_function_impl : std::is_function<T> {};
|
||||
struct is_function_impl : std::is_function<typename std::remove_pointer<T>::type> {};
|
||||
|
||||
template<typename T>
|
||||
struct is_function_impl<T, EnableIf<std::is_class<Unqualified<T>>>> {
|
||||
|
@ -64,9 +67,6 @@ using Bool = std::integral_constant<bool, B>;
|
|||
|
||||
template<typename T>
|
||||
struct Function : Bool<detail::is_function_impl<T>::value> {};
|
||||
|
||||
template<typename T>
|
||||
using Decay = typename std::decay<T>::type;
|
||||
} // sol
|
||||
|
||||
#endif // SOL_TRAITS_HPP
|
Loading…
Reference in New Issue
Block a user