Line 166 of button reads:
table.remove(buttons,button)
However, table.remove() is intended for use on numeric table indexes. You're using keys in the form of strings, so it's not suitable.
Switch it to this:
buttons[button] = nil
Edit:
Some more details are probably worthwhile here.
There are two ways you can use a Lua table: One is as an array, one is as a hashmap. These are somewhat different animals, but Lua allows you to treat one table as either
at the same time.
When you add entries to your table, if you use numerals to refer to their position, then you're treating the table as an array. If you use strings (or other objects), then you're treating it as a hashmap.
Let's say you build a table like this:
local myTable = {["someKey"] = "moo", ["someOtherKey"] = "moo2"}
Lua hashes the key names "someKey" and "someOtherKey", and uses the resulting numeric values to work out where to store the related data values ("moo" and "moo2") in memory. To find them again later - say you try to print myTable.someKey - all it needs to do is rehash the key name, and get the data value from the corresponding memory location. This is called hash-mapping, and while it's very inefficient in terms of memory usage, it's very convenient to use.
Let's say you build a table like this:
local myTable = {[1] = "moo", [2] = "moo2"}
In this case, Lua just uses the numbers directly to work out where to stick the data values - this is how an array is treated. Much more efficient to store, but it can potentially be more trouble to find certain values in a numerically indexed table - hash-maps are potentially much faster,
depending on what you're doing.
Certain commands, such as ipairs, table.insert() / table.remove(), #myTable and so on are only really intended for working on arrays. If you try to use them on a table which only uses hash-map style keys, they'll act like the table is
empty. If you have a table with both hash-map style keys
and numeric indexes, these commands will only operate on the numeric indexes.
If, on the other hand, you build your table up like an array, you won't be able to do what you're trying to do on line 359 in cutil. Your "moves" table is built that way (through your use of table.insert() all through the getMoves() function), but there you're trying to index into it using your "move" string.