dialogparameter-passinglauterbachunderflow

how to return a value from a called script with lauterbach practice scripts


I tried to follow the lib.cmm script, from lines 210-214, to return a value from a DO called script to my calling script, but get 'stack underflow' on my RETURN xx statement. My called script is an edited version of t32/demo/practice/dialogs/dialog_list.cmm.

What I'm trying to do should be easy, but I cannot determine how/why what I have done doesn't work nor how it differs from the ENTERDLG function in lib.cmm (in terms of return values).

Here are my two file's contents:

caller:

area.reset
LOCAL &GPU_choice
DO choose_CPU.cmm ENTERDLG
ENTRY %LINE &CPU_choice
print "cpu = &CPU_choice"

callee:

ENTERDLG:
LOCAL &CPU_choice

DIALOG
(&+
HEADER "Flash Programming"
POS 0. 0. 25. 1.
TEXT ""
POS 1. 0. 23. 1.
TEXT "CPU Type:"
POS 1. 1. 23. 3.

OptionA.SEL: LISTBOX "CPU1,CPU2" ""

;buttons OK (Default) and Cancel
POS 1. 11. 10. 1.
DEFBUTTON "OK" "CONTinue"

POS 14. 11. 10. 1.
BUTTON "Cancel" "GOTO cancel"

;define action when window is closed
CLOSE "GOTO cancel"
)

;set default selections
DIALOG.SET OptionA.SEL "CPU1"

;STOP command halts script execution
STOP

;script will continue here when "OK" button is clicked
;get selection
&CPU_choice=DIALOG.STRING(OptionA.SEL);

;close dialog window
DIALOG.END
RETURN &CPU_choice   <===============this line gives "stack underflow error"
ENDDO

;script continues here when Cancel is clicked"
cancel:
DIALOG.END
DIALOG.OK "Cancelled"

ENDDO

Solution

  • RETURN is for returning a value from a routine called with GOSUB inside the same script.

    To return a value to the script, which called the current script with DO, you have to pass the result with the ENDDO command.

    So in your example replace "RETURN &CPU_choice" with:

    ENDDO &CPU_choice
    

    See also https://www.lauterbach.com/reference_card_web.pdf (2nd page in the middle)