A console in Scol¶
The Scol console is very simple. It allows to display values and messages for debugging.
You must define a mask from the Scol settings (launch Scol, click right on the icon et choose Settings. Select the item "Mintenance").
To show the console : _showconsole
To hide the console : _hideconsole
To display a string in the console : _fooS
To display an integer in the console : _fooId
To display an hexa in the console : _fooI
To display a list in the console : _fooIList or _fooSList
Others functions _fooXXX are availables from the non-standard library Syspack.
How to have a customized console ?¶
This is an example, you can adapt at your case.
The code (by Loïc Berthelot, Scol language developer, 2000-2005) is :
/* By Loïc Berthelot, aka Neywen */
var CONSOLE_HIDE_LINENUM = 0;;
var CONSOLE_SHOW_LINENUM = 1;;
struct CONSOLE =
[
win_CSL : ObjWin, // console window
txt_CSL : S, // content
objtxt_CSL : ObjText, // 2d text object
font_CSL : ObjFont, // font object
flag_CSL : I // flag
] mkCONSOLE;;
typeof lastcsl = CONSOLE;; // console object
var LINECOUNT = 0;; // initial line count = 0
/* When the console window is destroyed, font and text object are destroyed before the window */
fun console_destroy (a, csl) =
_DSfont csl.font_CSL;
_DStext csl.objtxt_CSL;
1;;
/* When the window object is resized, the text object is resized too */
fun console_resize (win, csl, w, h) =
let _GETtextPositionSize csl.objtxt_CSL -> [x y _ _] in
_SIZEtext csl.objtxt_CSL (w-20) (h-20) x y;
1;;
fun console_getLineNum () =
let
if (LINECOUNT < 10) then
strcat strcat " " (itoa LINECOUNT) " : "
else if (LINECOUNT < 100) then
strcat strcat " " (itoa LINECOUNT) " : "
else
strcat (itoa LINECOUNT) " : "
-> linenum in
(
set LINECOUNT = LINECOUNT+1;
linenum;
);;
fun console_clear (csl) =
let if (csl == nil) then lastcsl else csl -> csl in
(
set csl.txt_CSL = "";
_SETtext csl.objtxt_CSL csl.txt_CSL;
);;
/* print a message in the console */
fun console_print (csl, msg) =
let if (csl == nil) then lastcsl else csl -> csl in
(
if ((csl.flag_CSL == CONSOLE_SHOW_LINENUM) || (csl.flag_CSL == nil)) then
set csl.txt_CSL = strcat strcat strcat csl.txt_CSL "\n" console_getLineNum msg
else
set csl.txt_CSL = strcat csl.txt_CSL msg;
_SETtext csl.objtxt_CSL csl.txt_CSL;
_SCROLLtext csl.objtxt_CSL 0 (_GETlineCount csl.objtxt_CSL)-1;
);
1;;
/* create the console window :
x, y : its position on the screen
w, h : its width and its height
flag : CONSOLE_HIDE_LINENUM ot CONSOLE_SHOW_LINENUM
the new console object is returned */
fun console_create (x, y, w, h, flag) =
let mkCONSOLE [nil nil nil nil flag] -> csl in
(
set csl.win_CSL = _CRwindow _channel nil x y w h WN_MENU|WN_SIZEBOX|WN_MINBOX "console";
_CBwinDestroy csl.win_CSL @console_destroy csl;
_CBwinSize csl.win_CSL @console_resize csl;
set csl.font_CSL = _CRfont _channel 12 0 FF_WEIGHT "arial";
set csl.objtxt_CSL = _CRtext _channel csl.win_CSL 10 10 w-20 h-20
ET_AHSCROLL|ET_AVSCROLL|ET_ALIGN_LEFT|ET_BORDER|ET_HSCROLL|ET_VSCROLL nil;
set lastcsl = csl;
csl;
);;
Here is a very basic example for use this console :
fun main ()=
_showconsole;
// we create the console
console_create 50 50 500 300 CONSOLE_SHOW_LINENUM;
let 50 -> counter in
while counter >= 0 do
(
// we write a message inside
console_print nil strcat "count : " itoa counter;
set counter = counter-1;
);
0;;
License : CC-BY-SA-2.0
Tutorial by iri
Updated by /
Updated by iri about 13 years ago · 1 revisions