-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any chance to pass an Action via an Event #12
Comments
If your
Not sure what you mean here. Do you have an example to clarify? |
Just thinking too complicated .. a plain old C function pointer works pretty well.
... and you can even pass lambdas and bind arguments there, which extends the usability dramatically.
... and default it to a do nothing:
In the end the problem was just how to store the function in the event class and I did not want std::function for the given reasons. Thanks for pulling me back to earth. |
Ah damn, binding does not work, see https://stackoverflow.com/questions/28746744/passing-lambda-as-function-pointer |
Yes, I think that's one reason why For the record: example usage of lamda function: elevator.cpp |
Yes I did see that example, but still had the trouble to pass it via the event. There are some nifty workarounds for std::function, not as complete, but for a void() function it would be easy enough, probably I'll go that way if I really need to. |
Finally, to close that topic, my solution:
And the event:
Usage (binding the stream for ChibiOS as example):
in transit
This has some potential to be more type-safe and probably shorter ... |
Probably this is more a general C++ question than it is a tinyfsm one, but maybe somebody did this already.
I have an event called ShouldEstimateAndSend which transits to a new state on a few conditions. I'd like to have it call transit<NewState>(ShoudEstimateAndSend::action_function).
Using std::function would work, but this introduces some runtime overhead and pulls in exception handling which is not what I like on my embedded target. Using a template event class 'breaks' inheritance and would need a template react function as far as I can see?!
Can't wiggle my head around this.
The text was updated successfully, but these errors were encountered: