oopinheritanceluaproperty-observer

Property observers in Lua


Is there way to add a property observer in Lua just like Swift does for WillSet and DidSet with properties?

For example, I have a object of display.newText and whenever I change it's text property. I need to do something other as well? Like object.text = "Changed"

I know I can add a method like setText() or something but I'm looking for property observers in Lua language.

Thanks in advance.


Solution

  • Use a proxy table. This is explained in Pil, Chapter 13.