V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
xatest
V2EX  ›  Lua

元表的__index和__newindex命名吐槽~

  •  
  •   xatest · May 8, 2013 · 4766 views
    This topic created in 4749 days ago, the information mentioned may be changed or developed.
    Lua中一个奇怪的设计:
    原始读索引是rawget(t, i),原始写索引是rawset(t, k, v)。
    元表的读索引却是__index,写索引是__newindex,这是什么命名,为什么不保持一致,就叫__getindex和__setindex?
    1 replies    1970-01-01 08:00:00 +08:00
    middleware
        1
    middleware  
       May 27, 2013
    Lua 5.2 document:
    Note that the metamethod (__index) is tried only when key is not present in table.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2783 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 01:40 · PVG 09:40 · LAX 18:40 · JFK 21:40
    ♥ Do have faith in what you're doing.