lua-users home
lua-l archive

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


>From steve@inquisit.com Mon Jun 22 15:58:32 1998
>
>The problem with the operator overloading approach is that there are more
>kinds of operations that you might want to perform on a vector or matrix than
>there are ACSII arithmetic symbols to be overloaded.
>(add, subtract, dot, cross, scale, invert, negate, size, etc)

not really. the tag method can be polymorphic and look at the types of
the arguments. for example, when handling "mult", you may check whether
one of the arguments is a number -- in this case, it's a "scale", not a full
matrix product. and so on.

>There is also the ordering problem. (does the standard ordering of all
>these operations apply properly to their vector and/or matrix usage?)

tag methods for the "arith" event occur in the standard ordering.
if you're not sure, look at the opcodes generated. use luac -l.

>I'd recommend a real object, something like this:
>
>Vector =
>{
>   array = {},
>   size = 0,
>   clone = clone
>}

>dotProduct = vec1:dot(vec2)
>crossProduct = vec1:cross(vec2)

this is perfectly good. operator overloading is something extra that can
be built on top of this.

>As for moving it to C, this is an option, but you might be carefull
>to make sure that the amount by which you'll be increasing your
>application's speed is worth sacrificing the flexilibity and
>development time savings of doing it in Lua.

my feelings exactly.

come on, folks, Lua is fast :-) (but remember that Lua is an interpreted
language -- it's not C).
--lhf