(no title)
adinisom | 7 months ago
Agreed re: making the state a static variable inside the function. Great for simple coroutines. I made it a pointer in the example for two reasons:
- Demonstrates access to the state variables with very little visual noise... "s->"
- For sub-coroutines that can be called from multiple places such as "delay" you make the state variable the first argument. The caller's state contains the sub-coroutine's state and the caller passes it to the sub-coroutine. The top level coroutine's state ends up becoming "the stack" allocated at compile-time.
kazinator|7 months ago
https://en.wikipedia.org/wiki/UML_state_machine#Hierarchical...