V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xatest
V2EX  ›  Lua

元表的__index和__newindex命名吐槽~

  •  
  •   xatest · 2013-05-08 22:21:58 +08:00 · 3943 次点击
    这是一个创建于 3999 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Lua中一个奇怪的设计:
    原始读索引是rawget(t, i),原始写索引是rawset(t, k, v)。
    元表的读索引却是__index,写索引是__newindex,这是什么命名,为什么不保持一致,就叫__getindex和__setindex?
    1 条回复    1970-01-01 08:00:00 +08:00
    middleware
        1
    middleware  
       2013-05-27 09:05:25 +08:00
    Lua 5.2 document:
    Note that the metamethod (__index) is tried only when key is not present in table.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2464 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 01:10 · PVG 09:10 · LAX 18:10 · JFK 21:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.