Add support for setting functions with operator[]

This commit is contained in:
Rapptz 2013-12-12 19:48:26 -05:00
parent 7cc8c93289
commit af0097fb7f
2 changed files with 10 additions and 5 deletions

View File

@ -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);

View File

@ -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