Skip to content

Allow M99 to return a named variable and value #1101

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

Open
wants to merge 1 commit into
base: 3.6-dev
Choose a base branch
from

Conversation

benagricola
Copy link
Contributor

@benagricola benagricola commented Mar 29, 2025

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 a V and R value:

; Return variable and value provided by caller
M99 V{param.V} R{param.R}

This will create, or override the local variable named by V with the value of R 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 a V 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 outside M99 as well.

@benagricola benagricola force-pushed the macro-return-vars-duet branch from bd01ea0 to 9e7e7b1 Compare March 31, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant