Ordered foreach(key, val in tbl)

Is there a way to control the order of the squirrel foreach() function?

For example - right now I have a table I am using as a register map for a device. Say the addresses start at 999 and go to 1011. When I use a foreach(key, val in tbl){//read and print the register} loop to read each register the registers start at 1008 and go to 1011 then jump back to 999 and go to 1007. Is there any way to make this an ordered function so I can read 999-1008 consecutively? Can I provide the ordering function to use?

Tables are implemented internally as hash tables, so no, you can’t provide the ordering function. If you want a container that preserves order, use an array of tables:
[ { key:999, val:myreg1 }, { key:1000, val:myreg2 }, ... ]