lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thanks everyone for the info. I know I should read the manual again and
again . 

If I have correctly understood the behaviour of the functions and I want
to have a function that adds 2 3D vectors . I can't do something like
this

	Function add_vector(x1,y1,z1,x2,y2,z2)
		return x1+x2, y1+y2, z1+z2
	end

as I'll be unable to use it like

	print(add_vector(get_position(1), get_position(2))

But maybe, the best solution is to have something like :

	Function add_vector(v1,v2)
		return v1[1]+v2[1], v1[2]+v2[2], v1[3]+v2[3]
	end

and do :

	print(add_vector({get_position(1)}, {get_position(2)})

Of course, I can also have the get_position() to return a table, so I
don't have to put the {}. And the add_vector can also return a table.
Even better I can set a metatable to the 3D vectors and they can
override the addition and stuff like that. 

Does anyone have a better approach/solution?

Gil Damoiseaux, ITV engineer, www.neurotv.be