Sign in to follow this  
sprite_hound

luabind - c++ member functions as lua non-member functions

Recommended Posts

I may have just got this the wrong way round in my head, but is it possible to have something like this:
-- lua code:

texture_handle = resources.add_texture("t_id", "t_file")
sound_handle = resources.add_sound("s_id", "s_file")


template<class T>
class ResourceManager {
public:
	unsigned int add(const std::string& type, const std::string& file);
	//...
};

class TextureManager : public ResourceManager<Texture> {
	//...
} textureManager;

class SoundManager : public ResourceManager<Sound> {
	//...
} soundManager;


luabind::module(state) [
	// How to register textureManager.add as resources.add_texture
	// and soundManager.add as resources.add_sound?
];


?

Share this post


Link to post
Share on other sites

int add_texture(std::string id, std::string file)
{
textureManager.add(id, file);
}

int add_sound(std::string id, std::string file)
{
soundManager.add(id, file);
}
...

luabind::module(state,"resources") [
def("add_texture", &add_texture),
def("add_sound", &add_sound)
];




Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this