Posted 15 August 2014 - 12:33 AM
Hi,
so I came across the concept of OOP in Lua and now I am really trying to get into this topic.
One of my problems in understanding is, the function of metatables.
The author of One of the tutorials says:
(http://www.computercraft.info/forums2/index.php?/topic/8393-oop-in-lua/)
"When we call this function, we can either call Person.getName(personObject) or personObject:getName(). Notice the colon instead of full-stop in the second call. This tells Lua to find the getName function in Person_mt.__index and pass personObject as the first parameter."
So does this mean, that the metatables are only used, so that you can use ":" instead of "." and you can leave out the self statement ?
Im pretty new to this realisation of the oop concept in lua so it would be nice to answer me in a very simple way ! :)/>
Thank you in advance
Kouksi44
so I came across the concept of OOP in Lua and now I am really trying to get into this topic.
One of my problems in understanding is, the function of metatables.
The author of One of the tutorials says:
(http://www.computercraft.info/forums2/index.php?/topic/8393-oop-in-lua/)
"When we call this function, we can either call Person.getName(personObject) or personObject:getName(). Notice the colon instead of full-stop in the second call. This tells Lua to find the getName function in Person_mt.__index and pass personObject as the first parameter."
So does this mean, that the metatables are only used, so that you can use ":" instead of "." and you can leave out the self statement ?
Im pretty new to this realisation of the oop concept in lua so it would be nice to answer me in a very simple way ! :)/>
Thank you in advance
Kouksi44