xatest
V2EX  ›  Lua

元表的__index和__newindex命名吐槽~

  •  
  •   xatest · May 8, 2013 · 4813 views
    This topic created in 4770 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   ·   1307 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 17:21 · PVG 01:21 · LAX 10:21 · JFK 13:21
    ♥ Do have faith in what you're doing.