tutorial on lua tables & data structures

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
spir
Citizen
Posts: 76
Joined: Wed Oct 17, 2012 1:12 pm

tutorial on lua tables & data structures

Post by spir » Wed Nov 14, 2012 6:18 pm

Hello,

after a short exchange in the thread tables for dummies, I started to write some material for a tutorial intended for the wiki. One chapter out of four planned is completed (however probably the biggest), plus an introduction, all in rough form. It is there (there is a file with the source text, and one with little pieces of code, so that we can run them and avoid polluting the tutorial with too many bugs ;)).

All comments, critics, and contributions welcome (reason why I uploaded). I don't intend to create the wiki page before more raw material is there, because i have a plan and content in mind: it would be stupid to invite everyone to edit directly already just to revert or rewrite because it does not fit. However, you can see a bit of the plan (section titles with empty content at the end of the text.) Probably it will be too big for a single page: we could let the introduction as portal, and from there point to sections on other pages.

In any case, if you feel motivated, you will have work: a tutorial is never good enough; Lua table form a big (and somewhat confused) topic; and english is a foreign language for me. (Also, I take the opportunity to restate my conviction that beginners are in the best situation to explain to other beginners: so, if you are one of them, you will be warmly invited to improve the tutorial.)

Denis

PS: seems would be really helpful: there are constantly questions directly or indirectly related to tables or data structuring, or manipulation of such beasts.
Last edited by spir on Wed Nov 14, 2012 9:08 pm, edited 1 time in total.
... la vita e estrany ...

User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: tutorial on lua tables & data structures

Post by Roland_Yonaba » Wed Nov 14, 2012 8:35 pm

All the links you gave point to that same thread, and I can't find those said tutorial files.
Or I may have missed something...I didn't have coffee since this morning... :awesome:

spir
Citizen
Posts: 76
Joined: Wed Oct 17, 2012 1:12 pm

Re: tutorial on lua tables & data structures

Post by spir » Wed Nov 14, 2012 9:09 pm

Roland_Yonaba wrote:All the links you gave point to that same thread, and I can't find those said tutorial files.
Or I may have missed something...I didn't have coffee since this morning... :awesome:
It's me missing coffee! Sh*it! Corrected the link to the online repo, thanks for telling,
Denis
... la vita e estrany ...

User avatar
verilog
Citizen
Posts: 97
Joined: Thu Nov 03, 2011 3:15 am
Contact:

Re: tutorial on lua tables & data structures

Post by verilog » Thu Nov 15, 2012 5:57 am

Hi spir,
Very nice and short tutorial, I enjoyed it :nyu: . It was a little bit hard to read, though, as the source file does not have format, but I understand is a raw first version.

Let me try to suggest something. One property I find very important and very usefull is that tables are stored by reference, so we can manipulate multiple references to a single object, for example:

Code: Select all

table1 = {1,2,3,4} 
table2 = table1 -- new reference to previous table
table2[3] = 5 -- we modify the reference's third item

for i=1, #table1, 1 do
	print("item #"..i.." from table1 is "..table1[i]) -- we see that the original item has been modified as well!
	print("item #"..i.." from table2 is "..table2[i])
end

spir
Citizen
Posts: 76
Joined: Wed Oct 17, 2012 1:12 pm

Re: tutorial on lua tables & data structures

Post by spir » Thu Nov 15, 2012 12:38 pm

verilog wrote:Hi spir,
Very nice and short tutorial, I enjoyed it :nyu: . It was a little bit hard to read, though, as the source file does not have format, but I understand is a raw first version.

Let me try to suggest something. One property I find very important and very usefull is that tables are stored by reference, so we can manipulate multiple references to a single object, for example:

Code: Select all

table1 = {1,2,3,4} 
table2 = table1 -- new reference to previous table
table2[3] = 5 -- we modify the reference's third item

for i=1, #table1, 1 do
	print("item #"..i.." from table1 is "..table1[i]) -- we see that the original item has been modified as well!
	print("item #"..i.." from table2 is "..table2[i])
end
Yes, you are right! A very important property, and topic for a tutorial. I take the opportunity to remind it is for the wiki: thus, when posted there, people like you are very welcome to contribute and improve. Actually, you are in the best situation for that. For instance on the topic of references, probably it's so obvious (and "natural", meaning what I'm used to) that talking about it dod not even come to my (poor :() mind

Let me suggest an example for references: a palette of colors used to draw or design. When the user modifies the "red" (an rgb triple) then the whole image must adapt.

What you have read is the first part of a plan, the one on tables "in general". There are 3-4 other parts planned:
2. tables used as arrays and others collections (set, map)
3. tables used as objects (records) and associated topics (tuples, classes)
4. tables for "linked structures" (graphs, trees, lists)
5 shortly back to tables in general

I just finished the part on arrays, and (since it's big compared to the rest) hope to finish part 2 in a while, maybe post it tonight. Thanks for reading and your comments, anyway.

Denis
... la vita e estrany ...

spir
Citizen
Posts: 76
Joined: Wed Oct 17, 2012 1:12 pm

collections

Post by spir » Thu Nov 15, 2012 7:26 pm

Hello,

I have completed a very rough version of the section on collections; with arrays, sets, maps. If you like, you can have a look the source (file tabstruct') there! (Checked the pointer, this time.) If ever I have enough time tomorrow and this week-end (and energy, this job sucks my ch'i !), I may finish this rough and create the wiki page before you can back from skiing.

Thank you,
Denis
... la vita e estrany ...

spir
Citizen
Posts: 76
Joined: Wed Oct 17, 2012 1:12 pm

objects....

Post by spir » Fri Nov 16, 2012 7:14 pm

Posted start of part about objects, with section on objects properly: source there (tutorial text still in wiki lang; and there is now a mini Löve app).

Denis
... la vita e estrany ...

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 59 guests