PDA

View Full Version : Lua Vector Class Library



yaustar
July 16th, 2006, 03:46
Note to news posters
I do not permit this Lua code snippet to be placed on ANY news page unless it is posted with the following quote:

This is just a small code snippet for Lua beginners/developers. This is not a release, game or application. Do not treat it as such.

2006-07-15
Here is a code library for a vector storage container as well as two demos to show how to use it. PM me if there are any errors in the library. It is basically a high level wrapper round the Lua table functions with bounds checking.

It should also be memory efficent and contain no memory leaks.

Demo 1 shows how and the effects of the functions.
Demo 2 shows how you can use it to draw all your objects in a scene (this one has 100).

Todo
Stack, Queue, Map structures ?

What is a Vector Storage Class?
It is a container that *should* hold multiple objects of one type (eg, a sprite or a number). This makes management of objects in an application much easier to handle and process.

For example, here is the code to draw 100 objects in Demo 2.

-- Draw the sprites (Notice how small the code is to draw 100 objects is)
for i = 1, VectorOfHackedSprites:Size() do
screen:blit (
VectorOfHackedSprites:Get(i).Int_XPosition,
VectorOfHackedSprites:Get(i).Int_YPosition,
VectorOfHackedSprites:Get(i).Img_Image
);
end

Demo 1
http://i2.tinypic.com/2058hmg.png
Demo 2
http://i2.tinypic.com/2058hsl.png