add reference to stack here

This commit is contained in:
ThePhD 2018-04-01 21:38:21 -04:00
parent 0c380da637
commit 612c1232e2
2 changed files with 5 additions and 5 deletions

View File

@ -15,21 +15,21 @@ int main() {
sol::state lua;
auto new_shared_ptr = [](sol::stack_object obj) {
auto new_shared_ptr = [](sol::stack_reference obj) {
// works just fine
sol::stack::modify_unique_usertype(obj, [](std::shared_ptr<ree>& sptr) {
sptr = std::make_shared<ree>(sptr->value + 1);
});
};
auto reset_shared_ptr = [](sol::stack_object obj) {
auto reset_shared_ptr = [](sol::stack_reference obj) {
sol::stack::modify_unique_usertype(obj, [](std::shared_ptr<ree>& sptr) {
// THIS IS SUCH A BAD IDEA AAAGH
sptr.reset();
// DO NOT reset to nullptr:
// change it to an actual NEW value...
// otherwise you will inject a nullptr into the userdata representation...
// which will NOT compare == to nil
// which will NOT compare == to Lua's nil
});
};

View File

@ -872,7 +872,7 @@ namespace sol {
}
template <typename T, typename F>
inline void modify_unique_usertype_as(stack_object obj, F&& f) {
inline void modify_unique_usertype_as(const stack_reference& obj, F&& f) {
typedef unique_usertype_traits<T> u_traits;
void* raw = lua_touserdata(obj.lua_state(), obj.stack_index());
void* ptr_memory = detail::align_usertype_pointer(raw);
@ -883,7 +883,7 @@ namespace sol {
}
template <typename F>
inline void modify_unique_usertype(stack_object obj, F&& f) {
inline void modify_unique_usertype(const stack_reference& obj, F&& f) {
typedef meta::bind_traits<meta::unqualified_t<F>> bt;
typedef typename bt::template arg_at<0> T;
modify_unique_usertype_as<meta::unqualified_t<T>>(obj, std::forward<F>(f));