lua-users home
lua-l archive

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


You have a base class for example

class CControl
{
  ..
  public:
    virtual void OnLeftbuttonDown() = 0;
};

and we derive a specific button control...

class CButton : public CControl
{
  ...
  void OnLeftbuttonDown() { printf(" left button pressed\n"); }
};

if we call ((CButton *)pControl)->OnLeftbuttonDown we'll get the 
left button pressed function called...

Now in LUA...
 i wish to register controls and script a GUI so i setup a control 
and create a new CButton from the LUA script...no problem

however i wish to overload the OnLeftbuttonDown function in LUA for 
this instance and call a LUA specific function (if i have defined 
it)...if i don't define it, it simply calls the default C++ version 
of the function..


Currently i am using simple tables, along the lines of a post i 
wrote yesterday...

Button  = { }

function SetupControls()
Button1 = { }
Button["Button1"] = { }

Button["Button1"].x = 10;
Button["Button1"].y = 15;
Button["Button1"].OnTest = Button1_OnTest;

RegisterButton("Button1");
end;

function Button1_OnTest()
	print("Button1 test");
end;

I am currently storing an extra pointer in my button class which i 
simply check for when the function in c++ is called, if it is set 
to  NULL i just call the default behaviour, otherwise i call the lua 
function...

this is the only 'easy' way i can see to do this although i'm 
guessing it may become a maintenance nightmare later on...

how do people normally go about resolving this kind of situation ?

regards