This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Termanater13's profile picture

2 Annoying Questions, I Really Want Answered

Started by Termanater13, 17 August 2013 - 11:41 PM
Termanater13 #1
Posted 18 August 2013 - 01:41 AM
I keep seeing many things in code. I look at code a try to pick it apart so I can see how it ticks to try and learn something from it, and the following questions relate to what I have seen.

[indent=1]First Question[/indent]
What is the difference with the following, and what is a good place to learn what that particular thing does.
  • test["first"]
  • test.first
  • test:first
[indent=1]Second Question[/indent]
What is a good object oriented tutorial. I see may scripts use this and I have no Idea how this part works, I do know that lua does have support for it, just not like java, and that's about all I know about it.
Bubba #2
Posted 18 August 2013 - 01:56 AM
Question 1)
The first two are the exact same thing. The second takes the table you're using and inserts it as the first argument to a function called with the colon operator. For example:

t = {
  ["hello"] = function(aTable)
    for i,v in pairs(aTable) do print(i,v) end
  end;
}

t.hello(t)
t:hello()

The two calls at the bottom do exactly the same thing, but one is shorter. A good place to learn this kind of thing is the PIL, though I'm not entirely certain where that particular bit is covered.

Question 2) This one depends on what exactly you're looking for. I would just google "Object Oriented Tutorial" and find a tutorial that suits you. The basics of object oriented programming are pretty much the same no matter what language, so go ahead and use whatever tutorial you understand best. After that, you can find Lua specific OOP tutorials on the PIL here.
oeed #3
Posted 18 August 2013 - 08:39 AM
It may not be the best tutorial, but you could check out this tutorial I wrote a while ago about how the OOP works in PearOS.

http://www.computercraft.info/forums2/index.php?/topic/12457-restored-how-to-make-a-graphical-and-object-oriented-os/page__p__114050#entry114050