Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter TwoLanguage Overview (continued)

2.10 Console and Console Applications

2.10.1 Console and Windows Applications

Legato operates in two modes: as a Windows Application or as a Console Application. There are significant differences in the operation and limitations for each. The principal difference is that a Windows application will have a main message loop, a frame window, and access to related edit windows.

By default, a console application runs the application in conventional command line mode with all output being directed to what is known as standard output or the stdout stream. Legato Basic can run as a conventional command line (LegatoC.exe) or as a windows command line (LegatoW.exe). Neither program has a frame window or message loop. Console applications can open message boxes and dialogs since dialogs, by default, have their own message loop. When running LegatoC, all message boxes are directed back to the console as text via stdout unless a dialog has been opened. Once a dialog is open, or when running LegatoW, message boxes behave in graphical form.

In order for any windowed application to run, it must contain a message loop or open a dialog box. The message loop retrieves messages from the Windows message queue, translates them (as required), and dispatches them to the appropriate window. This message loop is always running as a pseudo background task. In actuality, every menu function, rendering action, and foreground process action is the result of a window message dispatch.

When Legato Basic (LegatoC) is run, there is no message loop. If the console functions are run, they will only operate on the default console and all data is sent to and from the standard output/input or console window. This output can be routed or piped to other applications or destinations. For example:

D:\Apps\Legato>legatoc enumfiles.ls
File  1 enumfiles.ls
File  2 Legato.exe

D:\Apps\Legato>

In this case, the following simple script (which enumerates the files of the current folder) is run:

string   list[];
int      ix;

list = EnumerateFiles(GetScriptFolder() + "*.*");
ix = 0; 
while (list[ix] != "") {
  ConsolePrint("File %2d %s\r\n", ix+1, list[ix]);
  ix++;
  }     

The output from this script can be directed:

D:\Apps\Legato>legatoc enumfiles.ls > output.txt

D:\Apps\Legato>

The file “output.txt” will contain the list of files.

If that same script is run as an application desktop script, a separate console window will be opened:

Once a console window has been opened, it will remain open until manually closed (by pressing [X] or by executing ConsoleClose function).

2.10.2 The Console Window

When operating in window mode, the base application supports up to eight separate console windows, with the first (or zero index), as the default console. Consoles can be accessed via a console window handle. For most functions, not specifying a console window will result in the function using the default console. Synthetic control windows do not presently accept input.

As a console application, there is only the single shell console window (or pipe). All output from any specified console is direct there. Also note that the default program log will also be dumped to the console window upon completion of the script. Input via ConsoleGetLine and ConsoleGetCharacter is only allowed when running LegatoC.

Line endings are processed quite literally. A return 0x0D will move the current position to the start of the current line while a new line 0x0A will move the caret down a line.

2.10.3 Logs

When running LegatoC, error and default logs are dumped to console upon completion of execution (or abort). For LegatoW. they are run to a log window. Log output can be directed via command line options.

2.10.4 Console Window and Related Functions