Originally Posted by Edda
rawget(table, key) : I really don't see the point : example plz
|
Metatables magic
http://www.youtube.com/watch?v=CYxMfVy5W00
http://nova-fusion.com/2011/06/30/lu...bles-tutorial/
EDIT (example):
Lets set simple empty table called "t" with metatable "mt":
lua Code:
local defaults = { a = "hello world" }
local mt = { __index = defaults }
local t = {}
setmetatable(t, mt)
Now if you try:
It will print "hello world".
Key "a" is not present in table "t", but because we have defined metamethod __index in metatable, you will get value from "defaults" table.
If you try:
It will print "nil", because rawget returns the real value without invoking any metamethod.