From: John L. <jla...@gm...> - 2006-08-27 15:29:32
|
On 8/27/06, msh...@ya... <msh...@ya...> wrote: > > I am trying to make a easiest way to implement virtual method. Something like > wxLuaPrintout of howto override HasPage() etc.. method, but actually I did not quite get it > the how (as it touches some HasDerivedMethod() and some tag definition which I do not > have time to look at it yet). Is there a fast explanation and howto step, to do it? > It's fairly easy, but maybe not so obvious. The binding files (*.i) just contain the functions as for any other class, don't be fooled by wxLuaPrintout seemingly not having any functions, they are defined in the base wxPrintout binding. The c++ class has to implement the code to check to see if there is a lua function overriding it. See modules/wxbind/src/wxlprint.cpp for some examples. Note that we've decided to add a ref counted wxLuaState to the c++ class and then have to override the constructor, see bindings/wxwidgets/overrides.cpp wxLua_wxLuaPrintout_constructor instead of trying to lookup what lua_State we're coming from on the fly each time a function is called. Once inside the c++ function, see any of the wxLuaPrintout functions, you handle the args and do whatever is necessary then always call SetCallBaseClassFunction(false), otherwise you'll get recursion, if you call base_SOMEFUNCNAME() you always should get the base class function. If you can think of a way to automate this a little better that'd be great. There is one change I've been meaning to make however, we need a way to make naming wxLuaPrintout just wxPrintout in lua since the lua code doesn't need to know or care that it's really a wxLuaPrintout. Hope this helps, John Labenski |