lua-users home
lua-l archive

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

On Wed, Jun 11, 2014 at 1:52 PM, Lars Ruoff <> wrote:
Thanks Roland and all,

i have already a solution on the C(++) side. As i said, it's basically
struct VECTOR {
with some methods around it for utility functions.

Would it be better to expose those functions to Lua or use a Lua-side library?
The Lua scripts would need to get some vectors in tables, then do some calculation with it and return a bunch of other vectors.

And concerning my other initial question, would it feel "right" for a Lua coder to handle a 2D vector as a Lua table with elements "x" and "y"?

On Wed, Jun 11, 2014 at 8:18 PM, Roland <> wrote:
Hi Lars,

I don't know if you are looking for a solution on the C-side, but I remember
I have some implementations of vector classes in pure Lua. They might not be
the best, but just quick modules I have written as part of some personal
See  vec3.lua
(used in Lua port of Smallpt raytracer) and  vector.lua
(2d vectors used in a simulation of steering behaviors).
There is also this quite complete and clean module for 2d vectors, which is
part of a larger set of utilities, named HUMP. See  hump.vector
<>  .
And last,  lua-vec <>  . I haven't tested
this out, though,  but the API looks quite complete.

View this message in context:
Sent from the Lua-l mailing list archive at

As a consumer of this kind of stuff (as opposed to a domain expert):

I'd say it'd feel more natural to have it be { x, y } as opposed to {x = val, y = val}

you can also make a metatable for this so that x and y work, as well but I wouldn't do that. It's fine to represent a tuple as indexed values, as opposed to named pairs.