| Andreas Rozek |
|
TkLua_00a - a Console for TkLua ProgramsAn important issue of TkLua programs (running under a Win32 operating system) is the absence of a "console" for textual output. However, without such a console it becomes quite difficult to recognize error messages or to output some text, e.g. for debugging purposes. Fortunately, the integration of a console window turns out to be relatively simple, as long as it is only used for text output. "TkLua_00a" adds such a console to the "TkLua_00" example. This "Console" consists of a separate toplevel window containing a text widget and two associated scrollbar widgets. The window appears automatically as soon as the first text is printed onto it - and it disappears not before the associated program terminates (a click into the "close box" in the upper right corner of the console window just minimizes the window rather than closing it). Text output is achieved by means of the (global) methods print, write and writeln, known from "Lua_02" which have been redefined for that purpose. Furthermore, the function _ALERT has been extended such that Lua error messages will now show up in the console window as well. In order to test the new functions, the "main program" of "TkLua_00a" first prints the well-known text "Hello, World!". Then, an error is generated which should output its associated error message to the console. Finally, the periodic display of the actual date and time (once per second) checks whether the console is also available from within Tk event handlers. "TkLua_00a" should be invoked without any command line arguments lua TkLua_00a.lua and presents itself as follows:
The console window (containing some output from "TkLua_00a") looks as follows:
Source CodeThe source code of this example is available for download:
In order to make the console defined by "TkLua_00a.lua" available to other programming examples, its source code may be downloaded separately as a Lua script file:
References
|
| http://www.Andreas-Rozek.de/Lua/Acquainting/TkLua_00a_en.html | (last Modification: 15.04.2002) |