I've created an Object-esque table for a ball, and I wanted to have that object associated with it's own box2D body, shape, and fixture, for easy referencing in the future. Much pain and metatables later, I arrive at this solution:
Code: Select all
function ball.mt.__call(self,index,...)
--It's a series of look-ups. Nothing special,really.
if(type(ball[index])=='function') then --ball class
return ball[index](self,...);
elseif(type(self.fixture[index])=='function') then --love.physics.fixture
return self.fixture[index](self.fixture,...);
elseif(type(self.fixture:getBody()[index])=='function') then --love.physics.body
return self.fixture:getBody()[index](self.fixture:getBody(),...)
elseif(type(self.fixture:getShape()[index])=='function') then --love.physics.shape
return self.fixture:getShape()[index](self.fixture:getShape(),...)
end
end
Code: Select all
ball_obj("Function_Index",Argument1,Argument2)