diff --git a/src/weak_ref.cpp b/src/weak_ref.cpp index 245b26c2..2dcf7eb2 100755 --- a/src/weak_ref.cpp +++ b/src/weak_ref.cpp @@ -36,6 +36,7 @@ namespace { int weak_table_tag; + int impl_table_tag; } // namespace unnamed @@ -59,7 +60,28 @@ LUABIND_API void get_weak_table(lua_State* L) lua_pushlightuserdata(L, &weak_table_tag); lua_pushvalue(L, -2); lua_rawset(L, LUA_REGISTRYINDEX); + + } + +} + +LUABIND_API void get_impl_table(lua_State* L) +{ + + lua_pushlightuserdata(L, &impl_table_tag); + lua_rawget(L, LUA_REGISTRYINDEX); + + if (lua_isnil(L, -1)) + { + lua_pop(L, 1); + + lua_newtable(L); + lua_pushlightuserdata(L, &impl_table_tag); + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); + } + } } // namespace luabind @@ -74,15 +96,22 @@ namespace luabind , state(main) , ref(0) { + + get_impl_table(s); + lua_pushlightuserdata(s, this); + ref = luaL_ref(s, -2); + lua_pop(s, 1); + get_weak_table(s); lua_pushvalue(s, index); - ref = luaL_ref(s, -2); + lua_rawseti(s, -2, ref); lua_pop(s, 1); + } ~impl() { - get_weak_table(state); + get_impl_table(state); luaL_unref(state, -1, ref); lua_pop(state, 1); } diff --git a/src/wrapper_base.cpp b/src/wrapper_base.cpp index 9fb54a5d..8d479af2 100755 --- a/src/wrapper_base.cpp +++ b/src/wrapper_base.cpp @@ -34,6 +34,7 @@ namespace luabind { namespace detail LUABIND_API void do_call_member_selection(lua_State* L, char const* name) { object_rep* obj = static_cast(lua_touserdata(L, -1)); + assert(obj); lua_pop(L, 1); // pop self obj->crep()->get_table(L); // push the crep table