mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
add reference to stack here
This commit is contained in:
parent
0c380da637
commit
612c1232e2
|
@ -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
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue
Block a user