- Joined
- Oct 11, 2012
- Messages
- 711
Can anyone explain "metatable" in English? I have read the Lua 5.1 Manual and still don't get it. (I only know Jass)
Also, what does this mean?
I especially don't understand this part because it looks much different than the hashtable in Jass:
How come there is a function in a variable assignment? ...
Last, what does "handler" mean? Plain English and an easy understandable example would be great. Thank you.
Also, what does this mean?
JASS:
local x = {value = 5}
local mt = {
__add = function (lhs, rhs) -- "add" event handler
return { value = lhs.value + rhs.value }
end
}
setmetatable(x, mt) -- use "mt" as the metatable for "x"
local y = x + x
print(y.value) --> 10
local z = y + y -- error, y doesn't have our metatable. this can be fixed by setting the metatable of the new object inside the metamethod
I especially don't understand this part because it looks much different than the hashtable in Jass:
JASS:
local mt = {
__add = function (lhs, rhs) -- "add" event handler
return { value = lhs.value + rhs.value }
end
}
Last, what does "handler" mean? Plain English and an easy understandable example would be great. Thank you.