Page 1 of 1
help
Posted: Thu Aug 24, 2017 12:23 pm
by elijahsomeone
Hey, in a lot of other peoples code I see things like :new() :create(), :update() and much more. What exactly are these? I'm not very smart so i'll need a really good example. While you're hear I also need a good explanation of metatables I done really get them, thanks in advance!
Re: What are these things for and what are metatables?
Posted: Thu Aug 24, 2017 5:46 pm
by grump
Those are function calls. Try to read the
Lua documentation. You first need to understand the very basics like functions and how to call them before you can understand metatables.
By the way, "help" is the worst and laziest title you can choose for your questions. Don't do that.
Re: help
Posted: Thu Aug 24, 2017 6:08 pm
by zorg
Also, apart from "don't do that", what you -should- do is edit your post to change the title.
The colon (:) notation is similar to the dot (.) notation, but there's an extra implicit parameter added (whether or not we're talking about function definition or calls), basically, it's syntax sugar and you don't even need to use it. I had a nifty post on here that explained all this in a very compact way, but i can't be bothered to search for it.
Explaining metatables in so many words is hard, as others may also say, it's probably one of the "hardest" topics in lua. A very basic explanation could be this: lua metatables modify how lua works "behind the scenes" when you work with "normal" tables that have a metatable defined on them.
It can have many effects, it can override how arithmetic works, how indexing works, how it should behave if you try to index a missing element, and so on; the lua documentation lists all the metamethods you can use.