[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Lua script in games? (vectors)
- From: "Nick Trout" <nick@...>
- Date: Thu, 26 Jun 2003 20:10:43 -0700
> This is what I *really* want, purely for speed and ease-of-conversion,
> about time languages added a vector type to their integral types (in
> can do it with templates but compilation slows down terribly). Most
> applications have to deal with 3d in some form or other now which
> case when most of the languages were invented. ints and floats don't
> the mustard no more.
It's all want, want, want with you Cuthbert! Lua doesn't have ints! The
default is double, which covers floats, ints, 32bit unsigned ints (so
you can do 32 bit colour). Light userdata was added to replace C
pointers cast to numbers and passed round inside Lua IIRC.
> Sure you can just about do it in Lua but when almost every operation
> video game involves a vector of some sort it becomes obvious that
> that one area would create enormous gains. (for the gaming industry)
Yep, for the gaming industry, but what about the mathematicians who want
complex numbers and arbitrary precision integer math. Lua is easily
extensible to cope with these types. Python has both afore mentioned
types as built in types. Your job then is to *remove* them when you want
to embed Python in your game. I sat on a round table at GDC and a
programmer there was explaining how after stripping down Python you're
still left with a 500kb+ library. Lua is probably a 1/5th of this
including compiler, and a hell of a lot faster.
> Modern cpus now have ints, floats *and* vectors as integral types.
> Remember, you don't need to have floats as integral types either, you
> implement a floating point system in lua using integers and
But when you add two floats together in an interpreted language it's not
compiled down into assembler - it's executed by the VM. So executing
vector math on the VM using metamethods is not a whole lot different.
Now, I had this idea about statically compiling Lua scripts and
converting them into C++ for the release version, but having the nice
fast data/script driven development speed. If you were to do this you
would get a nice speed advantage and the C++ could then give you
hardware vector access. Since Lua is a dynamic language there are a
whole heap of issues with this (e.g. functions are first class objects,
environments etc. - it would have been easier with Lua 4!) but you'd be
closer to the advantages you mention. It was just an idea :-/