Tables

Defining tables

Tables in Hurdy work the same as in Lua and are defined in the same way:

var  t = {
  1, 2, 3,
  s = 5,
  [8] = 7,
  ["end"] = true
  then = false
}

-- defines the table with
-- t[1] = 1
-- t[2] = 2
-- t[3] = 3
-- t[8] = 7
-- t["s"] = t.s = 5
-- t["end"] = true
-- t["then"] = false

Hurdy allows both commas and newlines can be used as separators (mixing the two syntaxes is allowed):

var  t = {
  1
  2
  3
}

is equivalent to

var  t = {
  1,
  2,
  3
}

Trailing commas are allowed and are ignored.

Note

Keys used in the table constructor in the key = value format are allowed to be any identifier, including Lua and Hurdy keywords.

Accessing tables

Tables (and in general objects with an __index metamethod) can be accessed in the same way as Lua:

t.identifier
t["identifier"]
t:identifier() -- can only be used to call a method and is equivalent to t.identifier(t)

Note

When accessing a table using the . operator the identifier is allowed to be of any kind, including Lua and Hurdy keywords. However, when calling methods using the : operator the identifier must not be a Lua reserved keyword. This restriction does not apply to Hurdy-only keywords (e.g., var).

t.end -- this is ok, the compiler converts it to t["end"]
t["end"] -- this is ok
t.global -- this is ok
t:global() -- this is ok
t:end() -- not allowed