Allow M99 to return a named variable and value #1101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements #1038, for after v3.6.
I thought I would get this submitted as a potentially very simple (and in my opinion elegant) implementation that allows a value to be returned from a macro file, through the use of
M99
with aV
andR
value:This will create, or override the local variable named by
V
with the value ofR
in the calling macro or file.My inspiration for this was trying to implement a new RS485 communications protocol mcode that functions like the new
M261.1
, which takes aV
variable name and puts the returned data into that variable.I like this approach of setting a configurable local variable in the calling block nesting as it means the data will be garbage collected properly, and by allowing the return to write to an existing variable it is possible to call a macro in a loop (using it like a function for example) without having to name the variable differently every loop iteration.
NOTE: This is not implemented as part of
FileMacroCyclesReturn
as this function is called from outsideM99
as well.