[luabind] Help with adopt and Lua/C++ ownership
Brought to you by:
arvidn,
daniel_wallin
From: Sean B. <se...@gm...> - 2006-09-24 04:44:22
|
Hello all. I've got a derived class in Lua that I want to have garbage collected but I'm obviously not doing something right. I'm guessing the adopt policy gives me what I want but I haven't had any luck with it yet. Here is my base C++ class: class Foo { public: virtual ~Foo() { printf("Good-bye cruel world!\n"); } virtual void Greeting () { printf("Hello World\n"); } }; And here is the C++ Lua wrapper for it: class FooWrapper : public Foo, public luabind::wrap_base { public: virtual void Gretting() { call<void>("Greeting"); } static void static_Greeting(Foo* foo) { foo->Foo::Greeting(); } }; This is how I register this class in C++ for lua binding: module(lstate) [ class_<Foo, FooWrapper>("Foo") .def(constructor<>()) .def("Greeting", &Foo::Greeting, &FooWrapper::static_Greeting) ]; And here is the derived Lua class: class 'MyFoo' (Foo) function MyFoo:__init() super () print("MyFoo:__init called!") end function MyFoo:Greeting() print("Hello, Luabind World!") end function MyFoo:__finalize() print("MyFoo:__finalize() called!") end And finally, here I am invoking all this in Lua script: myTest = MyFoo() myTest:Greeting() myTest = nil collectgarbage() Here's the output from all this: MyFoo:__init called! Hello, Luabind World! I would expect __finalize() on the lua-derived MyFoo class to be called as well as the original C++ Foo destructor, yet neither is happening. Can someone clue me in to what I'm missing? Thanks, -seanba |