fork download
  1. obj_class =
  2. {
  3. __index = function(obj, func)
  4. return function(...)
  5. return getmetatable(obj)[func](obj, ...)
  6. end
  7. end,
  8.  
  9. add = function(obj, x, y)
  10. obj.x = obj.x + x
  11. obj.y = obj.y + y
  12. end
  13. }
  14.  
  15. local obj = setmetatable({ x = 1, y = 2 }, obj_class)
  16. obj.add(200, 400) -- yay!
  17. print(("x = %.9g, y = %.9g"):format(obj.x, obj.y))
Success #stdin #stdout 0s 15008KB
stdin
Standard input is empty
stdout
x = 201, y = 402