1

So I am writing a factory system to create objects and using lua to call them. however I am struggling to figure out how to expose them to lua using luaBridge.

I have a template factory:

    template <class T, class Id>
    {
         T* create(Id name)
         {
         }
         void register(Id name, BaseCreator<T>* func)
         }
         }
         std::map<Id, Creator<T>*> FunctionMap;
     }

The register function calls a inherited template create class that is derived from a virtual create to create objects of a certain type that is derived from a base object.

    class BaseObject{virtual void hello() = 0;}
    class DerivedObject : public BaseObject{void hello()}

    template <class T> class BaseCreator { virtual T*create = 0; }

    template <class Base, class derived> 
    class DerivedCreator 
    { 
           Base* create () 
           { 
                 return new derived; 
            }
     }

In C++ the factory is used like this:

     Factory<DerivedObject, string> objMap;
     objmap.register("Obj1", new DerivedCreator<DerivedObject, BaseObject>;
     BaseObject * Temp = objMap.create("obj1");

Do I have to expose the virtual base classes like BaseObject and BaseCreator to lua in order for me to create their derived types using lua? I have tried this and I get an error about creating an abstract object. Is there a way around this if I do have to expose the bass classes or is there another scripting language more suitable to handling this task?

md5i
  • 3,018
  • 1
  • 18
  • 32
yik
  • 65
  • 5
  • How do you use factories in Lua code? Are there several factories creating different object types? I am asking because I doubt that you have to use both dynamic and static polymorphism at the same time. – Dmitry T. Apr 27 '18 at 13:08

0 Answers0