Write documentation for tables
@@ -41,7 +41,7 @@ The Lua installed in the system might be from an incompatible version.
## The Pallene Type System
-Pallene's type system includes the usual Lua primitive types (`nil`, `boolean`, `float` and `integer`), as well as strings, arrays, functions, and records.
+Pallene's type system includes the usual Lua primitive types (`nil`, `boolean`, `float` and `integer`), as well as strings, arrays, tables, functions, and records.
There is also a catch-all type `value`, which can refer to any Lua or Pallene value.
### Primitive types
@@ -92,6 +92,35 @@ Nevertheless, Pallene is still able to infer then type of an array literal if th
local result = sum_floats({1.0, 2.0, 3.0})
```
+### Tables
+
+Table types in Pallene are writen as `{ field: t [, field2: t2, ...] }`, where `field` is an identifier and `t` is any Pallene type.
+For instance, `{ x: integer, y: integer }` is the type for a table with the fields `x` and `y` that are integers.
+
+Like arrays, Pallene tables are implemented as Lua tables and Pallene uses the same Lua syntax for their creation:
+
+```
+type point = {x: integer, y: integer}
+local p: point = {x = 10, y = 20}
+```
+
+Notice that all fields must be initialized, even fields with the type `value` which can be `nil`.
+Unlike Lua, Pallene doesn't consider an absent field to be `nil`; instead, it will trigger an error.
+
+It is possible to get and set fields in tables using the usual dot syntax:
+
+```
+p.x = 30
+print(p.x) --> 30
+```
+
+Pallene expects all fields to be initialized before their use.
+For example, if a function expects a table with the type `{x: value}`, the field `x` must be initialized regardless of the value in `x`.
+Passing a table with an unitialized field might trigger a runtime error.
+
+The length of the field should be at max `LUAI_MAXSHORTLEN` characters.
+In Lua 5.4, the default value for this constant is 40 characters.
+
### Functions
Function types in Pallene are created with the `->` type constructor.
