• <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)  編輯 收藏 引用

            久久亚洲精品成人av无码网站| 日本强好片久久久久久AAA | 香蕉久久夜色精品国产尤物| 亚洲国产香蕉人人爽成AV片久久| 免费精品国产日韩热久久| 久久精品日日躁夜夜躁欧美| 99精品久久精品一区二区| 久久免费视频6| 国产精品久久久久久福利漫画| 国产香蕉97碰碰久久人人| 久久久久久久女国产乱让韩| 国产精品天天影视久久综合网| 热久久国产欧美一区二区精品| 精品久久久久香蕉网| 中文字幕久久精品| 51久久夜色精品国产| 久久中文骚妇内射| 伊人久久五月天| 久久精品国产72国产精福利| 精品无码久久久久国产| 一个色综合久久| 狠狠人妻久久久久久综合| 国产91色综合久久免费| 久久久女人与动物群交毛片| 久久SE精品一区二区| 久久综合色老色| 亚洲国产成人久久综合一区77| 色偷偷888欧美精品久久久| 99久久国语露脸精品国产| 囯产极品美女高潮无套久久久| 很黄很污的网站久久mimi色| 婷婷综合久久中文字幕| 久久精品国产99久久无毒不卡| 伊人久久综合无码成人网 | 综合网日日天干夜夜久久| 久久精品视频一| 一极黄色视频久久网站| 久久夜色精品国产| 久久久久久亚洲精品影院| 午夜精品久久久久9999高清| 久久久受www免费人成|