lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


The tolua manual states that it supports polymorphism and the documentation 
apprears to confirm that.

To test this I created two classes, which are defined in packages as such:

module Habitat
{
	module Gui
	{
		class hbBaseComponent: public hbBaseTickable
		{
				virtual void SetSize(int sizex, int sizey);
				virtual void SetSize(float sizex, float sizey);
				virtual void SetPosition(float posx,
							float posy,
							char* hpos,
							char* vpos);
				virtual void SetPosition(int posx, int posy);
				virtual void SetPosition(float posx,float posy);
		};
	}
}


module Habitat
{
	module Gui
	{
		class hbStaticBitmap : public hbBaseComponent  
		{
			public:
				hbStaticBitmap();
				virtual ~hbStaticBitmap();
				hbStaticBitmap(	const char* name,
						const char* parent,
						const char* filename);
				virtual const char* ToString();
				string		mFilename;
		};
	}
}


I create an instance of the object in Lua, and attempt to call a function in 
the base class hbBaseComponent:

local staticBitmap = hbStaticBitmap:new(name, parent, filename)
staticBitmap:SetSize(1.0, 1.0)

I get an error saying:

	error: attempt to call field `SetSize' (a nil value)

The only way I can get polymorphism to work is by defining all functions from 
the base class hbBaseComponent in the sub-class package files. This seems to 
contradict what the tolua manual states. So am I doing something blatantly 
wrong, and if so, what? :)

Thanks
Mike