Member variables dependency policy
Max McGuire <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
I'm running into a problem with luabind automatically creating a dependency
between a member variable and the parent object. This functionality is
described in the documentation:
struct A { int m; };
struct B { A a; };
When binding B to lua, the following expression code should work:
b = B()
b.a.m = 1
assert(b.a.m == 1)
This requires the first lookup (on a) to return a reference to A, and not a
copy. In that case, luabind will automatically use the dependency policy to
make the return value dependent on the object in which it is stored. So, if
the returned reference lives longer than all references to the object (b in
this case) it will keep the object alive, to avoid being a dangling pointer.
In my case, B actually contains a pointer to A, and B does not own this
pointer. The object being pointed to is expected to outlive the instance B,
which causes a problem. When I access "a" from Lua, luabind creates a
dependency between a and b so that b won't be collected until a is
collected. Since a outlives b, this creates a condition where I accumulate
dependencies and Lua is never able to garbage collect them.
I was able to work around this by creating getter/setter methods for the "a"
member variable (without the dependency policy), but I'm wondering what the
correct way to solve this problem is.
Max
--
Technical Director
Unknown Worlds Entertainment
http://www.unknownworlds.com
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user