Tables ====== Defining tables --------------- Tables in Hurdy work the same as in Lua and are defined in the same way: .. code-block:: hurdy var t = { 1, 2, 3, s = 5, [8] = 7, ["end"] = true } -- defines the table with -- t[1] = 1 -- t[2] = 2 -- t[3] = 3 -- t[8] = 7 -- t["s"] = t.s = 5 -- t["end"] = true The only difference with Lua is that both commas and newlines can be used as separators (mixing the two syntaxes is allowed): .. code-block:: hurdy var t = { 1 2 3 } is equivalent to .. code-block:: hurdy var t = { 1, 2, 3 } Trailing commas are allowed and are ignored. Accessing tables ---------------- Tables (and in general objects with an :code:`__index` metamethod) can be accessed in the same way as Lua: .. code-block:: hurdy t.identifier t["identifier"] t:identifier() -- can only be used to call a method and is equivalent to t.identifier(t) .. note:: Just as in Lua, when accessing a table using the :code:`.` or :code:`:` operator is only possible if the identifier is not a Lua reserved keyword. This restriction does not apply to Hurdy-only keywords (e.g., :code:`var`). .. code-block:: hurdy t.end -- not allowed t["end"] -- this is ok t:global() -- this is ok This restriction may be removed in the future.