; Demonstrate saving the global state within a subroutine ; using the M73 autorestore feature ; O sub (DEBUG, imperial=#<_imperial> absolute=#<_absolute> feed=#<_feed> rpm=#<_rpm>) O endsub O sub M73 (save caller state in current call context, restore on return or endsub) ; g20 (imperial) g91 (relative mode) F5 (low feed) S300 (low rpm) ; (debug, in subroutine, state now:) o call (debug, arg=#1) o if [[#1] GT 0] ; if called with param #1 > 0, demonstrate restore-on-return (debug, executing return) o return o endif ; note - no exit M7x code needed - the following endsub or an ; explicit 'return' will restore caller state (debug, executing endsub) O endsub ; main program g21 (metric) g90 (absolute) f200 (fast speed) S2500 (high rpm) ; (debug, in main after endsub, state now:) o call ; ; show restore-on-endsub: o call [0] ; (debug, back in main after return, state now:) o call ; now show restore-on-return: o call [1] ; (debug, back in main, state now:) o call ; m2