-- meta methods


function vec_mt.__add(a, b)
	local at, bt = typeof(a), typeof(b);
	if (at == "Vector" and bt == "Vector") then
		local t = {};
		for k in next, a do
			t[k] = a[k] + b[k];
		end
		return vec.new(t);
	end
end

function vec_mt.__sub(a, b)
	local at, bt = typeof(a), typeof(b);
	if (at == "Vector" and bt == "Vector") then
		local t = {};
		for k in next, a do
			t[k] = a[k] - b[k];
		end
		return vec.new(t);
	end
end
	
function vec_mt.__mul(a, b)
	local at, bt = typeof(a), typeof(b);
	local aisNum = at == "number";
	if (aisNum or bt == "number") then
		local t = {};
		local v, n = aisNum and b or a, aisNum and a or b;
		for k in next, v do
			t[k] = v[k] * n;
		end
		return vec.new(t);
	elseif (at == "Vector" and bt == "Vector") then
		local t = {};
		for k in next, a do
			t[k] = a[k] * b[k];
		end
		return vec.new(t);
	end
end

function vec_mt.__div(a, b)
	local at, bt = typeof(a), typeof(b);
	if (at == "number") then
		local t = {};
		for k in next, b do
			t[k] = a / b[k];
		end
		return vec.new(t);
	elseif (bt == "number") then
		local t = {};
		for k in next, a do
			t[k] = a[k] / b;
		end
		return vec.new(t);
	elseif (at == "Vector" and bt == "Vector") then
		local t = {};
		for k in next, a do
			t[k] = a[k] / b[k];
		end
		return vec.new(t);
	end
end

function vec_mt.__unm(v)
	local t = {};
	for k in next, v do
		t[k] = -v[k];
	end
	return vec.new(t);
end

function vec_mt.__tostring(v)
	return table.concat(v, ", ");
end
	