Number Output Mode

These functions define how integer numbers are shown in TempLuator. None of them affect the way the real numbers are displayed.

Dec()
Hex()
Char()
Str()

DecHex()
HexDec()
CharDec()
CharHex()
DecChar()
HexChar()

SavedMode = SaveNumberOutputMode()
RestoreNumberOutputMode(SavedMode)

There are four functions that define basic number output modes:

Dec()

Show integers as decimal numbers. This is the default number output mode active when TempLuator starts.

int   NumberOne   = -100;
WORD  NumberTwo   = 65535;
DWORD NumberThree = 4294967295;
QWORD NumberFour  = 4294967296;

Hex()

Show integers as hexadecimal numbers with "0x" prefix and leading zeros if necessary.

BYTE  NumberOne   = 0xAA;
WORD  NumberTwo   = 0xFFFF;
DWORD NumberThree = 0x12345678;
QWORD NumberFour  = 0x00000000AABBCCDD;

Char()

Show integers as character constants enclosed in single quotes. Unprintable characters are shown as standard escape sequences. The characters in multibyte numbers are 'reversed' just as in standard C. Redundant zero bytes at the end are removed so this (quite famous) sequence of bytes 50 45 00 00 will be shown simply as 'EP' instead of much more complex (yet entirely valid) '\x00\x00EP' notation.

BYTE  NumberOne   = 'A';
WORD  NumberTwo   = 'ZM';
DWORD NumberThree = '12\t';
QWORD NumberFour  = 'BigValue';

Str()

Show integers as strings. This is rather non-standard in the C sense because C strings imply terminating zero. However, this mode sometimes may make the things much more simple and clean because the characters in multibyte numbers are not reversed and are easy to read. Redundant zeros at the end are removed.

BYTE  NumberOne   = "A";
WORD  NumberTwo   = "MZ";
DWORD NumberThree = "GUID";
QWORD NumberFour  = "QWORD:\t\t";

 

In addition, there are a few composite modes. Name of any composite mode consist of two parts, each of which is the name of a basic mode. Correspondingly, when a composite mode is set, each number is displayed twice: the first instance is shown normally in compliance with the first part of the mode's name, and the second one is shown as /* */ comment as the second part of the mode's name suggests:

DecHex()

BYTE NumberOne = 255 /* 0xff */;

HexDec()

BYTE NumberOne = 0xff /* 255 */;

CharDec()

BYTE NumberOne = '*' /* 42 */;

CharHex()

BYTE NumberOne = '*' /* 0x2A */;

DecChar()

BYTE NumberOne = 42 /* '*' */;

HexChar()

BYTE NumberOne = 0x2A /* '*' */;

 

There is a pair of functions that let you save and subsequently restore number output mode.

SavedMode = SaveNumberOutputMode()

This function returns the currently active number output mode. In fact, it returns a Lua table whose internal structure is not publicly documented and may change in the future so it is a bad idea to touch the members of this table. Instead, you just save the returned table in a variable and later pass this table to the corresponding restore function.

RestoreNumberOutputMode(SavedMode)

This function restores number output mode previously saved by the SaveNumberOutputMode() function. Naturally, it expects a single mandatory argument which must be a table that was returned by the latter function and will throw an error if the parameter passed to it is invalid. Here is an example of the two functions:

-- show integer numbers as decimal
Dec()
-- remember the current output mode
local PrevMode = SaveNumberOutputMode()

-- now we can freely change the number output mode as we wish and still be able to restore it later
Hex()
WORD "HexWord"

-- restore number output mode
RestoreNumberOutputMode(PrevMode)

-- as it easy to guess, now we have the Dec() number output mode which was active
-- when we called the SaveNumberOutputMode() function

Please note that all functions defined via the struct() function automatically save and restore the current number output mode so you don't have to worry about possible changes of the output mode and preserve it manually.