Factory.registerForType()

   
Type function
Library wattageTileEngine.ObjectSystem.Factory.*
Return value VOID
Keywords  
See also  

Overview

This function registers a constructor for a given type. This is necessary in order to support object graph persistence.

Syntax

Factory.registerForType( typeName, factoryMethod )
typeName (required)

String. Name of the type.

factoryMethod (required)

function. Method to use for creating new instances of the type.

Examples

local TileEngine = require 'plugin.wattageTileEngine'
local Object = TileEngine.ObjectSystem.Object
local ObjectFactory = TileEngine.ObjectSystem.Factory

local AnimalClass = {}
AnimalClass.new = function(nameParam)
    local self = Object.new({objectType="Animal"})

    local name = nameParam

    function self.sayName()
        print("Hello, my name is " .. name)
    end

    return self
end
ObjectFactory.registerForType("Animal", AnimalClass.new)