|
From: Paul K <pau...@ya...> - 2016-05-06 19:31:47
|
Hi John,
As I've been working through the code to figure out how to inherit a
new class from wxApp (similar to how wxLuaPrintout inherits from
wxPrintout), I wondered if it's possible to do most of it at the Lua
level (with a bit of help from C++).
If the binding generator identifies all wxwidgets classes that can be
passed as parameters and creates inherited *Lua* classes, the I can do
something like this:
local app = wx.wxGetApp()
-- recast wxApp to wxLuaApp
local newapp = app:GetInstance():DynamicCast("wxLuaApp")
newapp.MacOpenFiles = function(files) ... end
-- register the new app with wxwidgets
app:SetInstance(newapp)
This will also allow "true" inheritance from wxwidgets classes at the
Lua level, which I find lacking in wxlua right now (unless I'm missing
something).
The implementation would automate most of the work that would need to
be done manually for these inherited classes: (1) pick a class based
on whether it's passed as a parameter or not; if it's difficult to do
automatically, the list can be pre-assigned; (2) generate a proper
class definition; and (3) create stubs for virtual methods that will
check for properties assigned in the derived class (in the example
above it would be MacOpenFiles method).
One of the challenges I see is the initialization that needs to assign
the current lua state (m_wxlState) as I'm not sure when it needs to
happen (as DynamicCast doesn't create a new object). Maybe DynamicCast
can check if the cast is to one of wxLua* classes and do the
assignment? This problem remains even when the class definitions are
done "manually", so I'd be interested in any suggestions on how to
address this.
Is there a method to get the current Lua state (wxlState) to use in
virtual functions:
void wxApp::MacOpenFiles(const wxArrayString& filenames)
{
wxLuaState m_wxlState = s_wxlState // <== not sure what to put here
Related question: I'm trying to use wxEVT_LUA_ERROR and
wxEVT_LUA_PRINT form the Lua code, but can't find any examples on how
to set it up. Any pointers? Thank you.
Paul.
|