Я пытаюсь использовать luabind для привязки box2d, чтобы я мог использовать его в своих сценариях lua. Я столкнулся с проблемой, когда я не могу связать необработанные указатели с помощью luabind. Ниже мой код:
luabind::module(luaState)[
luabind::class_<b2Shape>("b2Shape")
];
luabind::module(luaState)[
luabind::class_<b2PolygonShape, luabind::bases<b2Shape>>("b2PolygonShape")
.def(luabind::constructor<>())
.def("GetChildCount", &b2PolygonShape::GetChildCount)
.def("SetAsBox", (void (b2PolygonShape::*) (float32 hx, float32 hy) ) &b2PolygonShape::SetAsBox)
.def("SetAsBox", (void (b2PolygonShape::*) (float32 hx, float32 hy, const b2Vec2& center, float32 angle) ) &b2PolygonShape::SetAsBox)
.def("TestPoint", (void (b2PolygonShape::*) (const b2Transform& transform, const b2Vec2& p) ) &b2PolygonShape::TestPoint)
.def("ComputeAABB", (void (b2PolygonShape::*) (b2AABB* aabb, const b2Transform& transform, int32 childIndex) ) &b2PolygonShape::ComputeAABB)
.def("GetVertexCount", (void (b2PolygonShape::*) () ) &b2PolygonShape::GetVertexCount)
.def("GetVertex", (const b2Vec2& (b2PolygonShape::*) (int32 index) ) &b2PolygonShape::GetVertexCount)
.def("Validate", &b2PolygonShape::Validate)
];
luabind::module(luaState)[
luabind::class_<b2FixtureDef>("b2FixtureDef")
.def(luabind::constructor<>())
.def_readwrite("shape", &b2FixtureDef::shape)
.def_readwrite("friction", &b2FixtureDef::friction)
.def_readwrite("restitution", &b2FixtureDef::restitution)
.def_readwrite("density", &b2FixtureDef::density)
.def_readwrite("isSensor", &b2FixtureDef::isSensor)
.def_readwrite("filter", &b2FixtureDef::filter)
];
Вот мой луа-код:
local anchorBodyDef = b2BodyDef()
anchorBodyDef.position = b2Vec2(20.0, 0.0)
local anchorShape = b2PolygonShape()
anchorShape:SetAsBox(2.0, 0.5)
local anchorFixDef = b2FixtureDef()
anchorFixDef.shape = anchorShape
Каждый раз, когда я пытаюсь присвоить форму моему приспособлениюDef с помощью anchorFixDef.shape = anchorShape
, lua выдает ошибку:
terminate called after throwing an instance of 'luabind::error'
what(): lua runtime error
Как бы вы связали что-то вроде const b2Shape* shape;
в luaBind, поскольку что-то вроде .def_readwrite("shape", &b2FixtureDef::shape)
вызывает у меня проблемы. Я видел в документах некоторый код, который использует интеллектуальные указатели в операторах привязки class_, но это не решило проблемы.
Спасибо.