Announcement

Collapse
No announcement yet.

Minor errors in 4DGL Prog Ref manual?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CasaDelGato
    replied


    Any chance that the manual will be updated with all the various bug reports soon?
    (Am I the only one that reads the manual?)

    Leave a comment:


  • meldavia
    replied


    The manual is incorrect, it should refer to 'endsub' rather than 'return'.
    When a function returns, it does however clean up the stack frame so even if a 'endsub' was forgotten, it will not cause a crash.

    gosub / endsub is particularly useful in dispatch loops in conjunction withe the lookup8 function and makes a very compact state machine,
    eg:- here is an example shell for a uSD card sector editor, it doesn't actually do anything, but gives you the general idea of the structure.

    func hexEdit(var sectHI, var sectLO)

    // keyboard dispatch loop within the function
    repeat

    while((ch := serin()) < 0); // wait for key
    gosub(lookup8(ch,
    /* UP ^E */ 0x05,
    /* DOWN ^X */ 0x18,
    /* LEFT ^S */ 0x13,
    /* RIGHT ^D */ 0x04,
    /* SECT- ^R */ 0x12,
    /* SECT+ ^C */ 0x03,
    /* SAVE ^P */ 0x10,
    /* ASCII ^F */ 0x06,
    /* HEX ^A */ 0x01
    )),
    (
    KEY_VOID,
    KEY_UP,
    KEY_DOWN,
    KEY_LEFT,
    KEY_RIGHT,
    KEY_PREV_SECTOR,
    KEY_NEXT_SECTOR,
    KEY_SAVE,
    KEY_ASCII,
    KEY_HEX
    );

    if(statusbar.txt) statusbar(1); // if we have a message, update status bar
    if(ch == ESC) goto cleanupAndExit; // if escape hit, exit the function
    forever

    KEY_VOID:
    statusbar.txt := "";
    beep(200,200);
    endsub; // key invalid

    KEY_UP:
    statusbar.txt := "Cursor Up";
    // do something here
    endsub;
    KEY_DOWN:
    statusbar.txt := "Cursor Down";
    // do something here
    endsub;
    KEY_LEFT:
    statusbar.txt := "Cursor Left";
    // do something here
    endsub;
    KEY_RIGHT:
    statusbar.txt := "Cursor Right";
    // do something here
    endsub;
    KEY_PREV_SECTOR:
    statusbar.txt := "Previous Sector";
    // do something here
    endsub;
    KEY_NEXT_SECTOR:
    statusbar.txt := "Next Sector";
    endsub;
    KEY_SAVE:
    statusbar.txt := "Save Sector";
    endsub;
    KEY_ASCII:
    statusbar.txt := "ASCII mode";
    // do something here
    endsub;
    KEY_HEX:
    statusbar.txt := "HEX mode";
    // do something here
    endsub;

    cleanupAndExit:
    // do cleanup/write-back etc here

    endfunc

    Leave a comment:


  • CasaDelGato
    started a topic Minor errors in 4DGL Prog Ref manual?

    Minor errors in 4DGL Prog Ref manual?

    On page 34 and 35, in the discussion of the GOSUB command, this statement is made:
    "** A common mistake is to forget the 'return' to return from a subroutine within a function."

    As far as I can tell, you DON'T use return from a subroutine, just the function.
    Am I wrong, or is the manual wrong?
Working...
X