-- $LastChangedDate: 2008-10-20 10:36:48 -0400 (Mon, 20 Oct 2008) $
-- This tests ability to inherit and override a base method.

-- Compile NewInstance()/DerivedClass().
dofile( "../lib.lua" )

Object = { }

function Object:new( name )
	-- If base class was instantiated directly, the base class will be passed as self.
	-- Or a derivative was instantiated which can chain ctors by passing its instance as self.
	if ( self == Object ) then
		self = lib.NewInstance( Object )  -- not chained, need new instance
	end
	self.name = name
	return self
end

function Object:GetClassName()
	return "Object"
end

function Object:GetName()
	return self.name
end

Dyna = lib.DerivedClass( Object )

function Dyna:new( name )
	self = lib.NewInstance( Dyna )
	Object.new( self, name )
  --self.name assigned by base ctor
	self.className = "Dyna"
	return self
end

function Dyna:GetClassName()
	return "Dyna"
end

object = Object:new( "Object" )
print( "object:GetClassName() = '" .. object:GetClassName() .. "'" )
print( "object:GetName()      = '" .. object:GetName() .. "'" )

dyna = Dyna:new( "Dyna" )
print( "dyna:GetClassName()   = '" .. dyna:GetClassName() .. "'" )
print( "dyna:GetName()        = '" .. dyna:GetName() .. "'" )
