A table in Lua consists of a set of key-value pairs. Basically, any object written in Lua is represented as a table. Grids, however, can be represented in multiple ways, using one of these algorithms.

The "flat list" algorithm baiscally stores a list of entries, each with a coordinate set, followed by the value. To look up the value, you would have to look up the list, and store the default value (also known as the "fill" value). This is an easier method because it can store a variable number of dimensions, and entries are flat, so it's flexible enough to save space by only storing values that were modified. A table with this algorithm is represented as { dimensions = {4, 2}, entries = { {1, 1, 0}, {4, 2, 0} }, fill = 4 } -- Please note that not all coordinate sets are occupied, as this representation only stores values different from 4.

Another algorithm (perhaps easier to predefine and much more commonly used) is the basic constructor. This algorithm stores an array of arrays. Here is a common example.

{ {0, 4,, 4, 4}, {4, 4, 4, 0} }

The only problem is that it uses more space on large grids, and it is more difficult to implement a "variable dimension" set, so it would be hard to initialize a 4D grid with the same API namespace that expects a 2D grid, which is why I decided to use the flat list algorithm. It saves space and can handle large arrays with less effort.

I am currently working on functions for converting grids and analyzing them. I'll be sure to post about it later.