I'm trying to return an std::shared_ptr from a method bound with Luabind, but it doesn't seem to recognize the type.
Luabind code:
module(lua)
[
class_<Character, BaseEntity, std::shared_ptr<Character> > ("Character"),
def("createCharacter", &Character::createCharacter)
];
createCharacter code:
std::shared_ptr<Character> Character::createCharacter(Game* gameInstance, const Character::CharacterSetup& characterSetup, string sprite, b2World* world)
{
return std::shared_ptr<Character>(new Character(gameInstance, characterSetup, sprite, world));
}
If I call this method in a Lua script, nothing gets returned, and execution stops there. However, if I change the method to return a Character*, it works as expected. Some googling around tells me that returning a shared_ptr shouldn't be a problem.
What am I doing wrong?
Also, I have this code so Luabind can understand std::shared_ptr:
namespace luabind
{
template <typename T>
T* get_pointer(std::shared_ptr<T> const& p)
{
return p.get();
}
}