@WB's answer is good, if you want something more magic, you can use this change using the __newindex __newindex :
local colour = setmetatable({}, { __newindex = function(self,k,v) rawset(self,k,v) rawset(self,v,k) end }) colour["red"] = 1 colour["blue"] = 4 colour["purple"] = 5 print(colour["purple"]) -- 5 print(colour[4]) -- blue
source share