An good (and lua/dll binding friendly) object factory?

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
Posts: 163
Joined: Sun Apr 14, 2013 8:51 pm

An good (and lua/dll binding friendly) object factory?

Post by hydexon » Thu May 22, 2014 10:22 pm

I'm in the way to create my own object factory implementation, and i need it to access it for Lua (OOLUA) and external DLL's, for my game engine based in Ogre so my current implementation is this:

Code: Select all


#include "GameObject.hpp"

#include <memory>
#include <string>
#include <map>
#include <functional>

namespace Core {
	class RegisterObjectHelper {
		RegisterObjectHelper(std::string className, function<GameObject* (void)> objectFactoryFunction);
	#define REGISTER_OBJECT(NAME, TYPE) static RegisterObjectHelper regObj(NAME, [](void)-> GameObject * {return new TYPE();});
	class GameObjectFactory
			static GameObjectFactory *getSingleInstance();
			void registerFactoryFunction(std::string name,  function<GameObject* (void)> objectFactoryFunction); //NON LUA BINDABLE!, i think.
			void registerFactory(std::string name, GameObject*);
			std::shared_ptr<GameObject> create(std::string name);
			std::map<std::string, function<GameObject* (void)>> factoryFunctionRegistry;
This code is taken from this: ... lusFactory if anyone interested.

GameObject class is a simple empty C++ class for now, but do you think is good for scalibility?, and OOLua friendly?, since i'm looking if OOLua support and external DLL, that kind of parameters (i'm talking about the function<GameObject* (void)> parameter and std::shared_ptr (i will gonna replace it with my own implementation) ) can affect the OOLua scripting o i need to look an C++11 compatible binding helpers?.

0 x

Post Reply