Contents
Table Value Lookup
Read-only lookup tables are supported. These are supplied as a multi-column file that is loaded separately from the program with a file extension of .SDTBL, and can be edited with a standard text editor.
It uses a hash table for lookup of the key value (the first column) so it is quite fast.
The lookup tables are loaded when the program starts and compiled in advance. This avoids any runtime overhead of having to construct a large table, and also avoids having to find filenames or paths of files.
Lookup Table Construction
A lookup table is a plain text file with the SDTBL extension, located in the TABLES/ directory with the programs.
The columns must be separated by the | symbol. All rows must have the same number of columns.
A row starting with # is ignored (if you would like a table header with column names, prefix it with #)
The first column (column 0) is always the ‘Key’ column, and duplicated values in the first column are forbidden.
The standard symbols for hex, strings, and integers from the SDPL language are supported for data. Variables are not supported.
An example of a lookup table file, lets call it DEMO.SDTBL:
01 | "Some text" 02 | "Some more text with some hex after it" AA BB CC
LOOKUP
A lookup against the table is performed with the LOOKUP command.
This would place “Some text” from the earlier example table in $VAR, as the key of that row is 01
LOOKUP /TABLE=DEMO /COL=1 %VAR | 01
The default column number is 1, so the /COL parameter could be omitted from the command above.
This command sets the status register TRUE if the table exists, the column exists, and a value was found. Otherwise, it sets FALSE, and the %VAR is cleared.
Iterative (row-based) access is also possible by using the /INDEX parameter.
LOOKUP /TABLE=DEMO /COL=1 %VAR | /INDEX 00
Since the status register is TRUE until an out-of-range request is made, you can simply iterate from 0 until the status is FALSE.