I was looking at the The Basics of Optimization referenced by Avigant. While I was reading through it, I found couple things to be interesting.
Stravant and BlueTaslem mentioned something about Intrusive Linked Lists. From the text alone, I immediately assumed some things.
- It is a form of tables.
- It is somewhat different from regular tables?
I googled it without specifying Lua and saw its common usage in C and C++. Here is the code of Intrusive Data Structure I saw. I have almost no knowledge on C language but this was the first information I found.
typedef struct intrusiveListNode {
struct intrusiveListNode *next;
struct intrusiveListNode *prev;
} IntrusiveListNode;
typedef is a C feature which creates a new name for an existing data type.
struct is basically a table.
IntrusiveListNode in the end is just a way to end the syntax?
Now, from my views, the actually object in the table never exists because it is telling that the intrusiveListNode to either go previous or next? I will leave this to here and move on to what Lua has to say about this.
Lua also had a similar approach and implemented a loop into the table
list = {next = list; value = "Zafirua"};
local l = list;
while l do
print(l.value);
l = l.next;
end;
It prints
Zafirua
I fail to understand this code. This is my understanding so far. Mind you, it is garbage.
- A Table named
listis created. nextis the identifier that is getting the objects from thelist. It's job is to return the next object in the list.valueis the object that is inside thelist.lis now going to gain all thelist's objects.- Implemented a loop
- prints value; hence prints
Zafirua - Since there are no more objects in the list, the loop will stop there.
Assuming from my that knowledge, I went on testing more stuff and failed miserably on this part.
list = {next = list; a = "Zafirua"; b = "Mini-Zafirua"; c = "-Zafirua" };
local l = list;
while l do
print(l.a);
l = l.next;
print(l.b);
end;
The typical attempt to index
nil value
I do not understand this. I am pretty sure my understanding is wrong in this. Can someone correct me and explain what my error is? Also an explanation on how this might be useful would be greatly appreciated as
References if you want to check them out

6 comments
How did the links suddenly break? It was working a moment ago.....Fixed it now.
I think what is happening is that when we say l = l.next, we are doing l = {l = {value},value}
The wiki has more information http://wiki.roblox.com/index.php?title=Linked_list
^ Thanks for the link.
your welcome
By the way, I have a similar question about optimization, memoized functions.