luabind를 사용하여 box2d를 바인딩하면 루아 스크립트에서 사용할 수 있습니다. luabind와 원시 포인터를 바인딩 할 수없는 문제가 발생했습니다.원시 포인터를 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)
];
가 여기 내 루아 코드입니다 : 다음은 내 코드입니다
terminate called after throwing an instance of 'luabind::error'
what(): lua runtime error
방법 : 나는 anchorFixDef.shape = anchorShape
를 사용하여 내 fixtureDef에 모양을 지정하려고
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_readwrite("shape", &b2FixtureDef::shape)
과 같은 것이 나에게 문제를주고 있기 때문에 luaBind에 const b2Shape* shape;
과 같은 것을 묶는 것에 대해 갈 것인가? class_ 바인딩 문에서 스마트 포인터를 사용하는 문서에서 코드를 보았지만 문제가 해결되지 않았습니다.
감사합니다.
포인트 1을 조사하겠습니다 만, 모양은 이미 b2Fixture의 포인터입니다. 내가 묶으려고하는 것이지. https://code.google.com/p/box2d/source/browse/trunk/Box2D/Box2D/Dynamics/b2Fixture.h#71 – Sun
@Sun, 여기서 추측합니다. 루아 바인드는 "알려진"유형에 대한 "readwrite"를 통해서만 할당을 지원할 수 있습니다. 그리고 포인터는 "알 수없는"유형입니다. –