sml icon indicating copy to clipboard operation
sml copied to clipboard

Examples of states with data

Open marcpawl opened this issue 5 years ago • 7 comments

Examples showing how data can be stored and changed in a state and state machine would be really helpful.

marcpawl avatar Apr 04 '19 14:04 marcpawl

How about this? https://boost-experimental.github.io/sml/examples/index.html#data

etam avatar May 14 '19 21:05 etam

Why does a copy of the 'data' object need to be passed into the state machine?

How can member functions of the data object be used as actions?

jonesmz avatar Sep 28 '19 03:09 jonesmz

Why does a copy of the 'data' object need to be passed into the state machine?

It doesn't need to be a copy. You can pass a pointer or a reference.

How can member functions of the data object be used as actions?

You can't do it directly. You have to create a proxy action.

See this example: https://boost-experimental.github.io/sml/examples/index.html#dependencies

etam avatar Sep 28 '19 10:09 etam

It doesn't need to be a copy. You can pass a pointer or a reference.

But why?

You can't do it directly. You have to create a proxy action.

Ah, that's really frustrating.

jonesmz avatar Sep 30 '19 19:09 jonesmz

It doesn't need to be a copy. You can pass a pointer or a reference.

But why?

To pass it to a guard or action as argument. (I hope I'm answering your question. If not, please elaborate)

You can't do it directly. You have to create a proxy action.

Ah, that's really frustrating.

A bit. SML takes something callable as action. It can be a pointer to a function or an object with call operator. In this model you can't just pass a plain method, because it needs an object to be called on. That's why you need at least a proxy like this: [](Foo* obj, Event ev) { obj->method(ev); }.

On a second thought, maybe you can try passing &Foo::method. If SML is using internally std::invoke (or something similar) it might work. But I haven't tested such approach.

etam avatar Sep 30 '19 19:09 etam

I appreciate you answering my questions, thank you.

To pass it to a guard or action as argument. (I hope I'm answering your question. If not, please elaborate)

This does answer my question, but this is not obvious at all in the examples of the project.

I see that you're marked as a contributor, but I know you're not the original author. Is this something you would be willing to work with me on? I'm happy to contribute insights into "What doesn't make sense", but currently I'm still in the "It doesn't make sense" phase of working with the library, so I can't just create PRs to enhance the documentation.

A bit. SML takes something callable as action. It can be a pointer to a function or an object with call operator. In this model you can't just pass a plain method, because it needs an object to be called on. That's why you need at least a proxy like this: [](Foo* obj, Event ev) { obj->method(ev); }.

On a second thought, maybe you can try passing &Foo::method. If SML is using internally std::invoke (or something similar) it might work. But I haven't tested such approach.

Well, you can see here what I want to do. Perhaps that'll elaborate on my goals and where I'm struggling to understand the best approach.

https://github.com/boost-experimental/sml/issues/298

jonesmz avatar Sep 30 '19 19:09 jonesmz

I see that you're marked as a contributor

I made a single PR to fix a minor thing. Most of the SML implementation is a black magic to me ;) Apart from that I'm a "simple user of this library". I've implemented one project with SML which gave me enough understanding to answer your questions so far.

Is this something you would be willing to work with me on?

I can't promise you a lot of my time. You know, life and other stuff keeps me quite busy.

I'm happy to contribute insights into "What doesn't make sense", but currently I'm still in the "It doesn't make sense" phase of working with the library, so I can't just create PRs to enhance the documentation.

Writing such things down is always a good feedback.

etam avatar Sep 30 '19 20:09 etam