lua-users home
lua-l archive

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


On 2/17/2011 11:00 AM, steve donovan wrote:
On Thu, Feb 17, 2011 at 11:48 AM, T T<t34www@googlemail.com>  wrote:
  vec3 = vec1 + vec2

to add together two arrays and the good elves take care of the rest,
but in Lua we have to write loops.
Well, it's traditionally done with objects, and this creates a great
deal of garbage (I recall Leo talking about this very thing.) The
elves turn out to be quite expensive.

IHMO, this is not the job of a standards-approaching implementation of
Lua, but a dialect that gets translated into Lua.

(A sophisticated template language like C++ can actually unroll this,
like the insanely clever work of Todd Verhuizen.)

What is the optimal form of the expression? Something like this (which
isn't easy on any eyes!)

vec3_1,vec3_2,vec3_3 = vec1_1 _ vect2_1, vec1_2 _ vect2_2, vec1_3 _ vect2_3

Now these vec objects become very interesting, like a kind of
statically-defined tuple. Wherever they appear, they need to be
expanded in this fashion.  To be Lua values, they need to be packed
into a list. Such a translator needs to track the tuple-ness of a
variable. I haven't worked out the detailed semantics but it could get
ugly.

An entertaining project for anybody with a bored graduate student is
to explore some ideas behind this kind of Template Lua, which converts
TL into regular Lua for fast execution.

steve d.


Hi Steve,

If you want fast vector ops, wouldn't it better to use LuaJIT FFI for the vectors? Then you can just store the 3 floats in a vector in native C arrays instead of using Lua tables. Should keep memory usage down and speed things up a lot.

Caveat: I haven't tried the FFI myself (yet), but I'm planning to have a look at this soon (tm).

Cheers,
Christian Tellefsen