Added Joint:setUserData and Joint:getUserData (resolves issue #894.)

This commit is contained in:
Alex Szpakowski
2014-06-05 20:56:43 -03:00
parent 3792dee4b4
commit 5dd23dffd1
15 changed files with 102 additions and 1 deletions
+23
View File
@@ -39,6 +39,16 @@ namespace box2d
class Body;
class World;
/**
* This struct is stored in a void pointer in the Box2D Joint class. For now, all
* we need is a Lua reference to arbitrary data, but we might need more later.
**/
struct jointudata
{
// Reference to arbitrary data.
Reference *ref;
};
/**
* A Joint acts as positioning constraints on Bodies.
* A Joint can be used to prevent Bodies from going to
@@ -95,6 +105,17 @@ public:
bool getCollideConnected() const;
/**
* This function stores an in-C reference to arbitrary Lua data in the Box2D
* Joint object.
**/
int setUserData(lua_State *L);
/**
* Gets the data set with setUserData. If no data is set, nil is returned.
**/
int getUserData(lua_State *L);
/**
* Joints require pointers to a Box2D joint objects at
* different polymorphic levels, which is why these function
@@ -117,6 +138,8 @@ protected:
World *world;
jointudata *udata;
private:
// A Joint must be destroyed *before* the bodies it acts upon,