[luabind] adopt policy and persistent objects after lua call
Brought to you by:
arvidn,
daniel_wallin
From: <cch...@uc...> - 2004-10-25 20:01:11
|
I'm using Luabind B7-rc4. I'm using it as a scene description language, and I'd like to have all the objects created in a lua function persist after that function has finished. My current setup is something like this: function createScene() scene = Scene() s = Shader() o = Object() s:setShader(s) scene:addObject(o) return scene end Where Scene, Object, and Shader are C++ classes with lua binds. I'm calling this function in C++ using: scene = call_function<Scene>(L,"createScene"); And this works really well, except that the Shader and Object objects are being garbage collected after the lua file is closed. Now I've read several other posts on how to use the adopt policy to transfer ownership of code, but only in binding a global C function to lua, not calling a lua function from C. My next step would be to add the adopt(_1) policy directive to setShader and addObject functions, and if I'm interpreting this right, it would mean that the parameters to those calls will be removed from lua garbage collection, but I'm running into a bit of a snag: currently my C++ method signature looks like: virtual void setShader(const Shader* s); my lua bind looks like this: .def("setShader",&Object::setShader,adopt(_1)) but I get the error: dependencies/build/include/luabind/detail/signature_match.hpp:248: no method `luabind::detail::adopt_policy<1>::only_accepts_nonconst_pointers::match' I've tried changing the signature to: virtual void setShader(Shader* s); but it still gives me the same error message. If anyone could shed some light on this, that would be great. Cameron |