mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
fix #593
This commit is contained in:
parent
a56a890adf
commit
6c6c89132b
|
@ -20,8 +20,8 @@
|
|||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// This file was generated with a script.
|
||||
// Generated 2018-02-20 16:44:34.136549 UTC
|
||||
// This header was generated with sol v2.19.0 (revision d7425db)
|
||||
// Generated 2018-02-21 06:23:41.439083 UTC
|
||||
// This header was generated with sol v2.19.0 (revision a56a890)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||
|
@ -1749,6 +1749,16 @@ namespace sol {
|
|||
return *std::forward<T>(item);
|
||||
}
|
||||
|
||||
template <typename T, meta::disable<is_pointer_like<meta::unqualified_t<T>>, meta::neg<std::is_pointer<meta::unqualified_t<T>>>> = meta::enabler>
|
||||
auto deref_non_pointer(T&& item) -> decltype(std::forward<T>(item)) {
|
||||
return std::forward<T>(item);
|
||||
}
|
||||
|
||||
template <typename T, meta::enable<is_pointer_like<meta::unqualified_t<T>>, meta::neg<std::is_pointer<meta::unqualified_t<T>>>> = meta::enabler>
|
||||
inline auto deref_non_pointer(T&& item) -> decltype(*std::forward<T>(item)) {
|
||||
return *std::forward<T>(item);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T* ptr(T& val) {
|
||||
return std::addressof(val);
|
||||
|
@ -15813,7 +15823,7 @@ namespace sol {
|
|||
typedef std::is_same<iterator_category, std::input_iterator_tag> is_input_iterator;
|
||||
typedef std::conditional_t<is_input_iterator::value,
|
||||
V,
|
||||
decltype(detail::deref(std::declval<captured_type>()))
|
||||
decltype(detail::deref_non_pointer(std::declval<captured_type>()))
|
||||
> push_type;
|
||||
typedef std::is_copy_assignable<V> is_copyable;
|
||||
typedef meta::neg<meta::any<
|
||||
|
@ -15849,11 +15859,11 @@ namespace sol {
|
|||
|
||||
static error_result get_associative(std::true_type, lua_State* L, iterator& it) {
|
||||
auto& v = *it;
|
||||
return stack::stack_detail::push_reference<push_type>(L, detail::deref(v.second));
|
||||
return stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(v.second));
|
||||
}
|
||||
|
||||
static error_result get_associative(std::false_type, lua_State* L, iterator& it) {
|
||||
return stack::stack_detail::push_reference<push_type>(L, detail::deref(*it));
|
||||
return stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(*it));
|
||||
}
|
||||
|
||||
static error_result get_category(std::input_iterator_tag, lua_State* L, T& self, K& key) {
|
||||
|
@ -16336,7 +16346,7 @@ namespace sol {
|
|||
else {
|
||||
p = stack::push_reference(L, it->first);
|
||||
}
|
||||
p += stack::stack_detail::push_reference<push_type>(L, detail::deref(it->second));
|
||||
p += stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(it->second));
|
||||
std::advance(it, 1);
|
||||
return p;
|
||||
}
|
||||
|
@ -16352,7 +16362,7 @@ namespace sol {
|
|||
}
|
||||
int p;
|
||||
p = stack::push_reference(L, k + 1);
|
||||
p += stack::stack_detail::push_reference<push_type>(L, detail::deref(*it));
|
||||
p += stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(*it));
|
||||
std::advance(it, 1);
|
||||
return p;
|
||||
}
|
||||
|
@ -16537,7 +16547,7 @@ namespace sol {
|
|||
}
|
||||
int p;
|
||||
p = stack::push_reference(L, k + 1);
|
||||
p += stack::push_reference(L, detail::deref(*it));
|
||||
p += stack::push_reference(L, detail::deref_non_pointer(*it));
|
||||
std::advance(it, 1);
|
||||
return p;
|
||||
}
|
||||
|
@ -16566,7 +16576,7 @@ namespace sol {
|
|||
if (idx >= static_cast<std::ptrdiff_t>(std::extent<T>::value) || idx < 0) {
|
||||
return stack::push(L, lua_nil);
|
||||
}
|
||||
return stack::push_reference(L, detail::deref(self[idx]));
|
||||
return stack::push_reference(L, detail::deref_non_pointer(self[idx]));
|
||||
}
|
||||
|
||||
static int index_get(lua_State* L) {
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// This file was generated with a script.
|
||||
// Generated 2018-02-20 16:44:34.892145 UTC
|
||||
// This header was generated with sol v2.19.0 (revision d7425db)
|
||||
// Generated 2018-02-21 06:23:41.719118 UTC
|
||||
// This header was generated with sol v2.19.0 (revision a56a890)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||
|
|
|
@ -532,7 +532,7 @@ namespace sol {
|
|||
typedef std::is_same<iterator_category, std::input_iterator_tag> is_input_iterator;
|
||||
typedef std::conditional_t<is_input_iterator::value,
|
||||
V,
|
||||
decltype(detail::deref(std::declval<captured_type>()))
|
||||
decltype(detail::deref_non_pointer(std::declval<captured_type>()))
|
||||
> push_type;
|
||||
typedef std::is_copy_assignable<V> is_copyable;
|
||||
typedef meta::neg<meta::any<
|
||||
|
@ -568,11 +568,11 @@ namespace sol {
|
|||
|
||||
static error_result get_associative(std::true_type, lua_State* L, iterator& it) {
|
||||
auto& v = *it;
|
||||
return stack::stack_detail::push_reference<push_type>(L, detail::deref(v.second));
|
||||
return stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(v.second));
|
||||
}
|
||||
|
||||
static error_result get_associative(std::false_type, lua_State* L, iterator& it) {
|
||||
return stack::stack_detail::push_reference<push_type>(L, detail::deref(*it));
|
||||
return stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(*it));
|
||||
}
|
||||
|
||||
static error_result get_category(std::input_iterator_tag, lua_State* L, T& self, K& key) {
|
||||
|
@ -1055,7 +1055,7 @@ namespace sol {
|
|||
else {
|
||||
p = stack::push_reference(L, it->first);
|
||||
}
|
||||
p += stack::stack_detail::push_reference<push_type>(L, detail::deref(it->second));
|
||||
p += stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(it->second));
|
||||
std::advance(it, 1);
|
||||
return p;
|
||||
}
|
||||
|
@ -1071,7 +1071,7 @@ namespace sol {
|
|||
}
|
||||
int p;
|
||||
p = stack::push_reference(L, k + 1);
|
||||
p += stack::stack_detail::push_reference<push_type>(L, detail::deref(*it));
|
||||
p += stack::stack_detail::push_reference<push_type>(L, detail::deref_non_pointer(*it));
|
||||
std::advance(it, 1);
|
||||
return p;
|
||||
}
|
||||
|
@ -1256,7 +1256,7 @@ namespace sol {
|
|||
}
|
||||
int p;
|
||||
p = stack::push_reference(L, k + 1);
|
||||
p += stack::push_reference(L, detail::deref(*it));
|
||||
p += stack::push_reference(L, detail::deref_non_pointer(*it));
|
||||
std::advance(it, 1);
|
||||
return p;
|
||||
}
|
||||
|
@ -1285,7 +1285,7 @@ namespace sol {
|
|||
if (idx >= static_cast<std::ptrdiff_t>(std::extent<T>::value) || idx < 0) {
|
||||
return stack::push(L, lua_nil);
|
||||
}
|
||||
return stack::push_reference(L, detail::deref(self[idx]));
|
||||
return stack::push_reference(L, detail::deref_non_pointer(self[idx]));
|
||||
}
|
||||
|
||||
static int index_get(lua_State* L) {
|
||||
|
|
|
@ -663,6 +663,16 @@ namespace sol {
|
|||
return *std::forward<T>(item);
|
||||
}
|
||||
|
||||
template <typename T, meta::disable<is_pointer_like<meta::unqualified_t<T>>, meta::neg<std::is_pointer<meta::unqualified_t<T>>>> = meta::enabler>
|
||||
auto deref_non_pointer(T&& item) -> decltype(std::forward<T>(item)) {
|
||||
return std::forward<T>(item);
|
||||
}
|
||||
|
||||
template <typename T, meta::enable<is_pointer_like<meta::unqualified_t<T>>, meta::neg<std::is_pointer<meta::unqualified_t<T>>>> = meta::enabler>
|
||||
inline auto deref_non_pointer(T&& item) -> decltype(*std::forward<T>(item)) {
|
||||
return *std::forward<T>(item);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T* ptr(T& val) {
|
||||
return std::addressof(val);
|
||||
|
|
|
@ -1274,3 +1274,55 @@ TEST_CASE("containers/custom indexing", "allow containers to set a custom indexi
|
|||
auto result3 = lua.safe_script("assert(c[-1] == nil)", sol::script_pass_on_error);
|
||||
REQUIRE(result3.valid());
|
||||
}
|
||||
|
||||
TEST_CASE("containers/containers of pointers", "containers of pointers shouldn't have their value_type's overly stripped") {
|
||||
sol::state lua;
|
||||
|
||||
class MyContainer {
|
||||
public:
|
||||
typedef int** iterator;
|
||||
typedef int* value_type;
|
||||
|
||||
std::vector<value_type> m_vec;
|
||||
|
||||
inline iterator begin() { return m_vec.data(); }
|
||||
inline iterator end() { return m_vec.data() + m_vec.size(); }
|
||||
inline void push_back(value_type v) { m_vec.push_back(v); }
|
||||
};
|
||||
int a = 500;
|
||||
int b = 600;
|
||||
|
||||
MyContainer ctr;
|
||||
ctr.push_back(&a);
|
||||
ctr.push_back(&b);
|
||||
lua["c"] = ctr;
|
||||
{
|
||||
auto result1 = lua.safe_script("ap = c[1]", sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
auto result2 = lua.safe_script("bp = c[2]", sol::script_pass_on_error);
|
||||
REQUIRE(result2.valid());
|
||||
int* ap = lua["ap"];
|
||||
int* bp = lua["bp"];
|
||||
REQUIRE(ap == &a);
|
||||
REQUIRE(bp == &b);
|
||||
REQUIRE(*ap == 500);
|
||||
REQUIRE(*bp == 600);
|
||||
}
|
||||
|
||||
std::unordered_map<int, int*> ptrs;
|
||||
ptrs[5] = &a;
|
||||
ptrs[6] = &b;
|
||||
lua["c2"] = ptrs;
|
||||
{
|
||||
auto result1 = lua.safe_script("ap = c2[5]", sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
auto result2 = lua.safe_script("bp = c2[6]", sol::script_pass_on_error);
|
||||
REQUIRE(result2.valid());
|
||||
int* ap = lua["ap"];
|
||||
int* bp = lua["bp"];
|
||||
REQUIRE(ap == &a);
|
||||
REQUIRE(bp == &b);
|
||||
REQUIRE(*ap == 500);
|
||||
REQUIRE(*bp == 600);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user