lua-users home
lua-l archive

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


Comments, bug reports and criticism of our unorthodox way are always welcome!

A spot of criticism: adding another 8 bytes to the Value union is too much, imo. Lots of stack copying on function calls etc, that will make an impact on the whole VM performance even when vectors aren't used. Again, imo (really imo - I can't stress this enough) - vectors should be made GC. Just copy the strings implementation - strings are plenty fast enough in Lua and are conceptually a 'vector' of characters, and this provides quick hashing benefits. By doing it this way, adding vectors is low cost.

Also there's additional advantages - ie the length could become variable (why limit it to 4?), and changing to doubles wouldn't blow out the Value type. Which would be a nice option to have as default, as mixing floats and doubles can cause all kinds of surprises for the unsuspecting.

I do like the decision to make them immutable.

And now on to dreaming territory:
imo the perfect vector extension to Lua would implement both vectors (tuple of numbers) and matrices (tuple of vectors of same dimension) - all the building blocks of a 3d app. Throw in tuples for good measure (anything that is neither a matrix nor a vector). All of these could be declared the same way, and let them be sorted out at runtime.

Perhaps hide the function call in a bit of parser higgery jiggery (say an OP_NEWTUPLE) and you have:

local tuple = [ "green eggs", "and ham" ]
local identitymatrix = [ [1, 0], [0, 1] ]
local vec = [ 1, 0, 0 ]
local fail_identitymatrix = [ vec, vec, vec ]

for i,v in ipairs(vec) do print(v) end

assert(type(tuple) == "tuple")
assert(type(vec) == "vector")
assert(type([[1], [2, 3]]) == "tuple")
assert(#identitymatrix == 2)
assert(#vec == 3)

(I'm aware this causes a parser nightmare when declaring tables in array form, ie { [1, 2], [2, 3] }, but I'm still dreaming here, maybe use <!!>?).

... and while you're at it throw in swizzles (newvec = vec.zzx), dot point and cross product operators (lets say .! and *!), perhaps vertices (collection of vectors) and vertexstrings (collection of vertices) and you have a pretty nifty language aimed at 3d graphics ;). Then you just need a genius (read: Mike Pall) to make a pixel shader/vertex shader runtime compiler (or cross compiler to hlsl) out of it, and... well, at this point I snapped back to reality.

But maybe some of that's doable..

- Alex