[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Integration of C++ objects into Lua
- From: "gradha29oct@... " <gradha29oct@...>
- Date: Tue, 25 Nov 2003 18:06:59 +0100
Hi.
I'm using lunar http://lua-users.org/wiki/CppBindingWithLunar
to integrate C++ and Lua. It works fine, and I had a question
but the author doesn't reply, so maybe somebody here can
help.
I want to push a C++ object (already created) to the Lua
stack. So I first push the name, then I use Lunar's push
method to create an object which can call my C++ object,
and finally lua_settable(L, GLOBALSINDEX) to make the name
available in the global space.
This is fine. Now, the problem is that I want to delete my
object and still run Lua fragments afterwards. The problem with
this is that the Lua proxy to my C++ object is still alive. I tried
a first approach pushing a nil value into the global name of the
object.
But what if a user has created an alias of that name? Example:
[C++] create object, push into lua as "c1"
[Lua] manipulate object, using methods and such
[C++] do something else
[Lua] one_copy = c1
[C++] delete object and push nil into "c1" global name
At this point, in the Lua environment c1 points to nil, but
one_copy points to the address where the C++ object lived.
More importantly, I can still invoke methods and overwrite the
memory which was used by the object's variables.
Is there any way I can get rid of all the Lua proxies of a C++
object I've deleted?