Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Class Types of Objects Returned from C++ Factory Methods #2

Open
jtpalmer opened this issue Aug 1, 2011 · 3 comments
Open

Comments

@jtpalmer
Copy link
Member

jtpalmer commented Aug 1, 2011

There are several methods, such as b2World::CreateJoint and b2Fixture::GetShape that have a return type that is the abstract base class corresponding to the object that is returned. In XS, we bless the returned objects to this class, not the subclass.

For example, the return type of b2World::CreateJoint is b2Joint. In C++, you can do this:

b2RevoluteJoint* joint = myWorld->CreateJoint(&jointDef);

In Perl, we have to:

my $joint = $world->CreateJoint($jointDef);
bless $joint, 'Box2D::b2RevoluteJoint";

I think it would be better to bless the returned objects directly into the subclass.

@kthakore
Copy link
Member

kthakore commented Aug 6, 2011

wat about having a Box2Dx::World that has

$world->CreateJoint( $jointDef, "Box2D::b2RevolouteJoint");

@jtpalmer
Copy link
Member Author

jtpalmer commented Aug 8, 2011

The joint type is stored in a public attribute of b2JointDef, so there is no need to specify the class when creating the joint.

@jtpalmer jtpalmer closed this as completed Aug 8, 2011
@jtpalmer jtpalmer reopened this Aug 8, 2011
@jtpalmer
Copy link
Member Author

b2BodyDef also has a public type attribute that can be used in the same way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants