With the latest update came the ability to use the sky.include(filename) function
If you have taken a look at the "Base Classes" samples provided in the Asset Library, then you've probably seen this strange looking line of Lua:
- Code: Select all
EntityBaseClass.__index = EntityBaseClass
and wondered what it means??
Basically, .__index is what Lua calls a "metamethod". Whenever you attempt to access an absent field in a Table, Lua doesn't just return a nil value, it actually looks for this metamethod first, and gets the result from it (if it exists).
The use of the __index metamethod for inheritance is so common that Lua provides a shortcut. Despite the name, the __index metamethod does not need to be a function: It can be a table, instead. When it is a function, Lua calls it with the table and the absent key as its arguments. When it is a table, Lua redoes the access in that table.
(from http://www.lua.org/pil/13.4.1.html)
This functionality allows the creation of a "prototype" Table that can be "inherited" by other Tables. This can lead to a long chain of Tables that "inherit" from the previous one in the chain (just be careful the chain doesn't get too long, as it can be slow).
An example of how to use this is on the lua-users wiki:
http://lua-users.org/wiki/InheritanceTutorial
Hope this helps
Shando