Wishlist "OVERLOAD" / PRINT

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
Berkeley
Posts: 94
Joined: Jun 08, 2024 15:03

Wishlist "OVERLOAD" / PRINT

Post by Berkeley »

There should be a way especially to switch the output of "PRINT", even during runtime. But it should be much more universal, to be able to replace ("overwrite") built-in functions like SCREENRES too. In case of PRINT you may redirect the output from stdout to a given function - as a string. The line break code should be -reliably(!)- only 13, and translated by the standard output routine into \r\n for WinDOS or \n for Linux. The comma in "PRINT a,b" may be code 9 / \t in the string.

For example my RETROGRA library uses an own console I call "VT 2000", "terminal emulation". First, it would be sensible to switch all outputs of PRINT to this console, so you don't have to type "rgPRINT" instead. Second, PRINT has an own syntax unusable by own subroutines => commas and semicolons. Third, the console might become once a separate library, then you'll have to exchange every "rgPRINT" with a new command. If you could switch the output, you only have to include a library like "curses.bi" and PRINT would put out automatically to the curses window. Fourthly: it's sensible to switch during runtime, especially to put out some system messages, maybe for the log files, although the rest of the output should go somewhere else (the graphical canvas).

PRINT is of course a very special case; any other sub might be simply replaced, C style. - Pointer to a function with identical arguments. But the PRINT expressions aren't even C/C++ compatible. Though at least those expressions lead to a simple string. So you might in this case not "overload" PRINT, but redirect its output. - Maybe we assume, that "PRINT" is short for "PRINT #0" - "channel 0" is stdout for PRINT, stdin for INPUT; #-1 might be stderr. And these "channels" may be redirected to subroutines taking one string as parameter. Therefore you won't use a syntax like "OVERLOAD PRINT WITH rgPRINT" but e.g. "DIRECT #0 OUTPUT TO rgPRINT"
Post Reply