lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I use ToLua to create the bindings for my C++ class A.
I create an instance of this class in my C++ code.
That instance is now visible to C++ but not to Lua.
I then expose the instance to Lua; the instance is visible to both C++ and Lua. Is the variable in Lua a reference to the C++ instance, or is it a completely separate entity (instance)?

I am assuming that "expose the instance to Lua" is to pass its pointer to a Lua variable, right?
In that case, Lua has only a reference to the C++ instance.

I delete the instance in C++. The variable still exists in Lua, but what value does it have? I presume that the deletion doesn't automatically get filtered to Lua. How would I deal with this?

You should take care of that. This problem also happens in C/C++ programs, when you have more
than one variable pointing to a single instance.

I create an instance of an object in Lua. The instance is only visible to Lua and not C++. I delete the instance in Lua, and the C++ code is none the wiser that a new instance ever existed.

well, the instance was created by the C++ constructor, but you have no C++ variable holding this instance.

-- waldemar