-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Support definition of methods similar to state variables #382
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! This needs documentation on the wiki.
I documented it here: https://github.com/icyphy/lingua-franca/wiki/Writing-Reactors-in-Cpp#using-methods |
Shouldn't this be in the language specification? (Even if currently only supported by Cpp). |
Oh, right. I completely forgot about the language specification. I also added a description of methods there. |
This PR adds support for the definition of methods in LF code. Methods are defined similarly to state variables. They can be invoked from reactions and allow encapsulating certain functionality and also enable code reuse between reactions. Currently, we only have preambles for defining functions, but this is not always sufficient as methods might need to access parameters and state variables or call other methods. In particular, we noticed that we need methods for porting complex ROS nodes to LF in a practical way. This PR also adds a test case, which also serves as a usage example.
This MR depends on #375 and should only be merged once #375 is merged.