Say I have a table, and a script indexed a value. How would I go about detecting what it has indexed and changing the value?
This would require using metatables
-- example
local t = setmetatable({} --[[ this is the original table; the metatable is an addon to it ]],
{ --[[ this is the metatable ]]
__index = function(self, key)
-- __index is called when a value that doesn't exist in the table is indexed
-- for example, if a script indexes table[2] and '2' doesn't exist, this metamethod will be called
-- 'key' is the index that was indexed, for example, if you index table["button"], key will be 'button'
-- this will NOT call for keys that exist in the table; if table["index"] exists in the table, this metamethod will not be called
print(key)
end
})
local null = t.NULL -- prints 'NULL'
-- it prints 'NULL' because the key 'NULL' doesn't exist in the original table (it's blank)