It is certainly possible. You can overload the __newindex __newindex to translate myValue to setMyValue , and then call it in the table. Example:
local meta = { __newindex = function(t, key, value) local setterName = "set" .. key:sub(0, 1):upper() .. key:sub(2) local setter = t[setterName] if setter == nil then error("Setter " .. setterName .. " does not exist on table") end return setter(t, value) end } local table = { setMyValue = function(self, v) print("Set value to " .. tostring(v)) end } setmetatable(table, meta) table.myValue = "Hello"
This will print "Set Hello."
You might want to overload __index to do the same, but with getMyValue .
source share