Advertisement
AI_UBI

Meta example lua

Feb 15th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.58 KB | None | 0 0
  1. local META = {}
  2. META =
  3. {
  4.     __index = function(tbl, key) return META[key] end,
  5.  
  6.     x = 0,
  7.     y = 0,
  8.  
  9.     setX = function(lhs, v) x = v end,
  10.     setY = function(lhs, v) y = v end,
  11.     getX = function(lhs) return x end,
  12.     getY = function(lhs) return y end,
  13.  
  14.     getDistance = function(lhs, rhs)
  15.         return math.sqrt(math.pow(lhs.x-rhs.x,2) + math.pow(lhs.y-rhs.y,2))
  16.     end
  17. }
  18.  
  19. function Vector2(x, y)
  20.  
  21.     local TBL = setmetatable({}, META)
  22.  
  23.     TBL:setX(x)
  24.     TBL:setY(y)
  25.  
  26.     return TBL;
  27.  
  28. end
  29.  
  30. print("VAL:",Vector2(12,2):getX())
  31. print("VAL:",Vector2(12,2).x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement