Closed vbartusevicius closed 3 months ago
I am using Lambda all the time. The issue is that you cannot capture "this" easily. I pass the this pointer in as a user argument. Here is the syntax I am using:
ControlId = ESPUI.addControl (
uiControltype,
Title.c_str (),
GetDataValueStr (),
color,
TabId,
[] (Control * sender, int type, void * UserInfo)
{
if (UserInfo)
{
static_cast <cControlCommon *> (UserInfo)->Callback (sender, type);
}
},
this);
Yes, that works. I just want to ask if there is an error in the documentation or the code. Because the docs say:
I think the type-definition could be adjusted to allow capturing this
.
Personally, I use the UserInfo
for different purposes. Wrapping additional structure to incorporate this
seems not the best idea.
I happen to use this. You can point at any structure you want and interpret it any way you want. Ultimate flexibility.
I am using Lambda all the time. The issue is that you cannot capture "this" easily. I pass the this pointer in as a user argument. Here is the syntax I am using:
ControlId = ESPUI.addControl ( uiControltype, Title.c_str (), GetDataValueStr (), color, TabId, [] (Control * sender, int type, void * UserInfo) { if (UserInfo) { static_cast <cControlCommon *> (UserInfo)->Callback (sender, type); } }, this);
Thanks a lot! I was missing this!!!
Describe the bug Trying to use a lambda callback as in the README:
Getting an error:
Using PlatformIO and
s00500/ESPUI@^2.2.3