fork(1) download
  1. local mytable = {}
  2.  
  3. local mt = {}
  4.  
  5. function mt.__newindex(t,k,new_value)
  6. local previous_value = mt[k]
  7. rawset(mt,k,new_value)
  8.  
  9. if previous_value and new_value == nil then
  10. print "__remove() triggered"
  11. end
  12. end
  13. mt.__index = mt
  14.  
  15. setmetatable(mytable, mt)
  16.  
  17. mytable.key = 123
  18. print(mytable.key)
  19.  
  20. mytable.key = nil
  21. print(mytable.key)
  22. -- your code goes here
Success #stdin #stdout 0s 15008KB
stdin
Standard input is empty
stdout
123
__remove() triggered
nil