--****************************************************************************** --* * --* File: ASCIITable.lua Revision: 1.0 * --* * --* Purpose: prints a simple ASCII table on "stdout" * --* * --* Creation: 05.03.2002 Last Modification: 07.11.2004 * --* * --* Environment: Lua 5.0, LuaJava 1.0b3, Java 1.4.2 * --* * --* Author: Andreas Rozek Phone: ++49 (7031) 222305 * --* Bunsenstraße 80/1 Fax: - * --* D-71032 Böblingen EMail: Info@Andreas-Rozek.De * --* Germany * --* * --* URL: http://www.Andreas-Rozek.de/ * --* * --* Copyright: the software is published under the "GNU Lesser General Pub- * --* lic License" (see "http://www.fsf.org/copyleft/lesser.html" * --* for additional information) * --* * --* Comments: this script was originally written using Lua 4.0 and then * --* converted to Lua 5.0 * --* * --****************************************************************************** local HexTable = { [0]='0';'1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' }; --****************************************************************************** --* * --* isPrintable decides if a given character is printable or not * --* * --****************************************************************************** function isPrintable (Code) return ((Code >= 32) and (Code <= 126)) or ((Code >= 160) and (Code <= 255)); end; --****************************************************************************** --* * --* main program * --* * --****************************************************************************** println(); println("ASCIITable - prints a simple ASCII table"); println(); --**** print table header **** print(" | "); for Col = 0,15 do print("-"..HexTable[Col].." "); end; print("| \n"); println("----+"..string.rep('-',16*3+1).."+----"); --**** println table body **** for Row = 0,15 do print(" "..HexTable[Row].."- | "); for Col = 0,15 do local Code = Row*16+Col; if (isPrintable(Code)) then print(" "..string.char(Code).." "); else print(" "); end; end; print("| "..HexTable[Row].."-\n"); end; --**** println table footer **** println("----+"..string.rep('-',16*3+1).."+----"); print(" | "); for Col = 0,15 do print("-"..HexTable[Col].." "); end; print("| \n"); exit();