meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
lua:meta [2015/07/19 13:20] – niziak | programming:lua:meta [2020/07/03 09:48] (current) – ↷ Page moved from lua:meta to programming:lua:meta niziak | ||
---|---|---|---|
Line 32: | Line 32: | ||
</ | </ | ||
- | IF mettables are normal table, so it is possible to use the same table also as metatable to save some resources | + | If mettables are normal table, so it is possible to use the same table also as metatable to save some resources |
<code lua> | <code lua> | ||
setmetatable (NormalTable, | setmetatable (NormalTable, | ||
+ | </ | ||
+ | |||
+ | **setmetatable(table, | ||
+ | <code lua> | ||
+ | local NormalTable = {} | ||
+ | setmetatable (NormalTable, | ||
+ | </ | ||
+ | to | ||
+ | <code lua> | ||
+ | local NormalTable = setmetatable ({}, {}) | ||
</ | </ | ||
===== Metamethods ===== | ===== Metamethods ===== | ||
- | | + | [[http:// |
- | * **%%__newindex%%** is called when value to not existsing | + | |
- | * **%%__metatable%%** | + | [[http:// |
+ | |||
+ | | ||
+ | * **%%__index%% = function (table, key)**, return value of fucntion is returned as result. | ||
+ | * **%%__index%% = table** | ||
+ | * to access table key without invoking %%__index%% methamethod use **rawget(table, | ||
+ | |||
+ | | ||
+ | * **%%__newindex%% = function | ||
+ | | ||
+ | |||
+ | * **%%__metatable%%** | ||
* **%%__call%%** - if somebady calls table as function, this metamethod will be called | * **%%__call%%** - if somebady calls table as function, this metamethod will be called | ||
- | * **%%__tostring%%** - | + | * **%%__tostring%%** - when **tostring(table)** is called |
+ | * **%%__len%%** | ||
===== Synctatic sugar ===== | ===== Synctatic sugar ===== | ||
Line 65: | Line 87: | ||
class: | class: | ||
class.method(t, | class.method(t, | ||
- | </codE> | + | </code> |