@@ -1088,16 +1088,50 @@ class luaw {
1088
1088
return pusher<std::decay_t <T>>::push (*this , std::forward<T>(value));
1089
1089
}
1090
1090
1091
- // / Push with an user given hint type.
1091
+ /* *
1092
+ * @brief Push with an user given hint type.
1093
+ *
1094
+ * Hint specifies what type of value we want to push into Lua.
1095
+ *
1096
+ * If Hint is luaw::function_tag, push the value as a funcion.
1097
+ *
1098
+ * If Hint is luaw::class_tag, push the value as an userdata. And the value
1099
+ * must be a class or a raw/smart pointer to class.
1100
+ *
1101
+ * The origin value must be convertible to Hint.
1102
+ * So, Hint Can't be reference.
1103
+ *
1104
+ * Hint could have cv- property.
1105
+ *
1106
+ * @tparam Hint Expected type to be pushed as.
1107
+ * @tparam T Origin type of value.
1108
+ * @param value The value to be pushed.
1109
+ * @return int
1110
+ */
1092
1111
template <typename Hint, typename T>
1093
1112
std::enable_if_t <!std::is_same<Hint, T>::value, int > push (T&& value) {
1094
- static_assert (
1095
- std::is_same<Hint,
1096
- std::remove_cv_t <std::remove_reference_t <Hint>>>::value,
1097
- " Hint should not be const/volatile/reference" );
1113
+ static_assert (!std::is_reference<Hint>::value,
1114
+ " Hint should not be reference" );
1115
+ return __push<Hint, T>(std::forward<T>(value), 0 );
1116
+ }
1117
+
1118
+ private:
1119
+ // Firstly, try pusher<DecayHint>::template push<TargetT, Y>.
1120
+ template <typename Hint, typename T>
1121
+ auto __push (T&& value, int )
1122
+ -> decltype(pusher<std::decay_t <Hint>>::template push<Hint, T>(
1123
+ *this , std::forward<T>(value))) {
1124
+ return pusher<std::decay_t <Hint>>::template push<Hint, T>(
1125
+ *this , std::forward<T>(value));
1126
+ }
1127
+
1128
+ // Secondly, try pusher<DecayHint>::push.
1129
+ template <typename Hint, typename T>
1130
+ auto __push (T&& value, ...) -> decltype(auto ) {
1098
1131
return pusher<std::decay_t <Hint>>::push (*this , std::forward<T>(value));
1099
1132
}
1100
1133
1134
+ public:
1101
1135
// / Copy and push a value already in the stack.
1102
1136
void pushvalue (int idx = -1 ) { lua_pushvalue (L_, idx); }
1103
1137
0 commit comments