So if I have a table of colours:
colour["red"] = 1
colour["blue"] = 4
colour["purple"] = 5
and I want to add red to blue, I can easily get the number values of red and blue, but then with the value 5, can I get it to return "purple" without scanning the whole table?
You would need a table with both hash and array part, if colour numbers are unique. For example:
colour["purple"] = 5
colour[5] = "purple"
You can create a little helper function that would facilitate populating the table, such as:
function addColour(coltab, str, val)
coltab[str] = val
coltab[val] = str
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With