• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            的筆記

            隨時隨地編輯

            Metatables

            參考資料

            Referenced Values, Metatables, and Simple Inheritance>

            http://phrogz.net/lua/LearningLua_ValuesAndMetatables.html

            Metatable In Lua 淺嘗輒止
            http://www.cnblogs.com/simonw/archive/2007/01/17/622032.html

            扯淡

            metatable只是一個普通的table,當你它他當做metatable來用的時候,他就成了metatable:
               setmetatable( theFirstTable, theOtherTable )

            如果一個table有一個metatable,碰巧的是這個metatable有一寫特殊的關鍵字,則在使用這個table的時候,會發生一個寫有趣的事情:
             function gettable_event (table, key)
               local h
               if type(table) == "table" then
                 local v = rawget(table, key)
                 if v ~= nil then return v end
                 h = metatable(table).__index
                 if h == nil then return nil end
               else
                 h = metatable(table).__index
                 if h == nil then
                   error("...");
                 end
               end
               if type(h) == "function" then
                 return h(table, key)      -- call the handler
               else return h[key]          -- or repeat operation on it
            end

                也就是,你訪問表,其實最終訪問到表的metatable上去了。這些就是lua mirror a cplusplus class的基本原理。細節是復雜的,也很晦澀。


            Metatables

            15個重載方法(http://www.lua.org/manual/5.1/manual.html#2.8)

            We call the keys in a metatable events and the values metamethods. In the previous example, the event is "add" and the metamethod is the function that performs the addition.

            1. "add": the + operation.
            2. "sub": the - operation. Behavior similar to the "add" operation.
            3. "mul": the * operation. Behavior similar to the "add" operation.
            4. "div": the / operation. Behavior similar to the "add" operation.
            5. "mod": the % operation. Behavior similar to the "add" operation, with the operation o1 - floor(o1/o2)*o2 as the primitive operation.
            6. "pow": the ^ (exponentiation) operation. Behavior similar to the "add" operation, with the function pow (from the C math library) as the primitive operation."unm": the unary - operation.
            7. "concat": the .. (concatenation) operation.
            8. "len": the # operation.
            9. "eq": the == operation. The function getcomphandler defines how Lua chooses a metamethod for comparison operators. A metamethod only is selected when both
            10. objects being compared have the same type and the same metamethod for the selected operation.
            11. "lt": the < operation.
            12. "le": the <= operation.
            13. "index": The indexing access table[key].
            14. "newindex": The indexing assignment table[key] = value.
            15. "call": called when Lua calls a value.

            posted on 2011-07-02 20:49 的筆記 閱讀(298) 評論(0)  編輯 收藏 引用

            色欲综合久久躁天天躁| 国内精品综合久久久40p| 99久久精品国产免看国产一区| 亚洲精品乱码久久久久久| 久久精品亚洲精品国产色婷| www.久久热.com| 久久久精品国产亚洲成人满18免费网站| 久久中文字幕无码专区| 久久九九久精品国产免费直播| 久久99精品久久久久久久久久| 日日狠狠久久偷偷色综合免费 | 久久久久精品国产亚洲AV无码| 久久综合久久自在自线精品自| 人人狠狠综合久久亚洲88| 无夜精品久久久久久| 97久久久久人妻精品专区| 99久久国产亚洲综合精品| 久久九九全国免费| av午夜福利一片免费看久久| 无码任你躁久久久久久久| 免费精品99久久国产综合精品| 中文字幕久久久久人妻| 久久91精品国产91久| 人人狠狠综合久久亚洲高清| 国产一区二区三区久久| 色8久久人人97超碰香蕉987| 国内精品伊人久久久久妇| 无码人妻少妇久久中文字幕| 99久久99久久精品国产片果冻| 国产精品久久久久久一区二区三区| 久久香综合精品久久伊人| 亚洲美日韩Av中文字幕无码久久久妻妇| 国产ww久久久久久久久久| 国产69精品久久久久99尤物| 69SEX久久精品国产麻豆| 久久精品天天中文字幕人妻| 亚洲AV无码成人网站久久精品大| 久久国语露脸国产精品电影| 欧美亚洲国产精品久久| 亚洲午夜久久久久妓女影院| 亚洲成色www久久网站夜月|