-- $LastChangedDate: 2008-10-20 09:36:48 -0500 (Mon, 20 Oct 2008) $

print( "Running vec.lua" )

XX = 0
YY = 1
ZZ = 2

-- 2D vector class (index starts as zero).
Vec2_ = {}
function Vec2( x, y )  -- this is a ctor
	t = { [XX] = x, [YY] = y }
	setmetatable( t, Vec2_ )
	Vec2_.__index = Vec2_
	return t
end
function Vec2_:__tostring()
	return tostring(self[XX]) .. "," .. tostring(self[YY])
end

-- 3D vector class (index starts as zero).
Vec3_ = {}
function Vec3( x, y, z )  -- this is a ctor
	t = { [XX] = x, [YY] = y, [ZZ] = z }
	setmetatable( t, Vec3_ )
	Vec3_.__index = Vec3_
	return t
end
function Vec3_:__tostring()
	return tostring(self[XX]) .. "," .. tostring(self[YY]) .. "," .. tostring(self[ZZ])
end

-- Test.
assert( test )  -- ensure C++ exported these
assert( test.SetVec3 )
assert( test.GetVec3 )

-- By SetVec3() C++ will specifically test for the values 123,456,789.
-- And by GetVec3(), Lua checks that C++ returns 123,456,789
-- as a table indexed from 0 (zero rather than one).
print( "Testing passing vec3 between Lua and C++" )
v = Vec3( 123.0, 456.0, 789.0 )
test.SetVec3( v )
v2 = test.GetVec3()
assert( type(v2) == "table" )
if ( v2[0] ~= 123.0 or v2[1] ~= 456.0 or v2[2] ~= 789.0 ) then
	error( "GetVec3() failed" )
end
