On Wed, 7 Apr 2021 13:45:06 -0700 (PDT) Tobias T wrote:
TT> I've added a draft PR with my current idea/implementation start:
TT>
https://github.com/wxWidgets/wxWidgets/pull/2316
Thanks, I'll look at it a.s.a.p. but probably after 3.1.5 release, as this
won't make it into it (unless you really want it to?).
TT> I've implemented the success via GetInt() in the new event. Might make
TT> sense to provide a convince IsError() or similar.
Yes, I think a wrapper like this would be nice.
TT> TT> It would of course be nice to have some sort of direct lambda support,
TT> TT> but I think for the sake of consistency it wouldn't make sense.
TT> >
TT> > Using Bind() with a lambda is not that bad of a substitute, but if we
TT> > really wanted, we could provide a simple wrapper function doing it,
TT> > i.e. binding the lambda, calling RunScriptAsync(), and then unbinding
TT> > it.
TT> >
TT> That kind of wrapper sounds interesting but I'm not sure how that would
TT> be implemented (named/defined).
In pseudo code just like what I described in English above, i.e.
void RunScriptAsync(
const wxString& script,
const std::function<void (wxWebViewEvent&)> handler)
{
Bind(wxEVT_WEBVIEW_SCRIPT_RESULT,
[this, handler](wxWebViewEvent& e)
{
handler(e);
Unbind(wxEVT_WEBVIEW_SCRIPT_RESULT);
});
}
Except for the questions of lifetimes, I don't see why wouldn't this work?
VZ