







Bought pokemon platinum and the case looks a little faded so I'm worried it might be fake
your*
Only know of these ways but kinda curious if there's more
Proceedural(?)
function make\_vector(x,y)
return {
x = x or 0,
y = y or x or 0
}
end
function print\_vector(vector)
print( "X: ".. vector.x .. " Y: " .. vector.y)
end
local pos1 = make\_vector(10,15)
print\_vector(pos1)
pos1.x = 0
print\_vector(pos1)
No metatables
local Vector = {}
function Vector.new(x,y)
local self = {}
self.x = x or 0
self.y = y or self.x
function self.print()
print("X: " .. self.x .. " Y: " .. self.y)
end
return self
end
local pos1 = Vector.new(10,15)
pos1.print()
pos1.x = 0
pos1.print()
metatables
local Vector = {}
Vector.__index = Vector
function Vector.new(x,y)
local self = setmetatable({},Vector)
self.x = x or 0
self.y = y or self.x
return self
end
function Vector:print()
print("X: " .. self.x .. " Y: " .. self.y)
end
local pos1 = Vector.new(10,15)
pos1:print()
pos1.x = 0
pos1:print()