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
    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 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;


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

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 

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 ?