• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Nausicaa
V2EX  ›  程序员

门外汉偷偷问下 table 表里值的问题?

  •  
  •   Nausicaa · May 18, 2020 · 2719 views
    This topic created in 2369 days ago, the information mentioned may be changed or developed.

    (```) a { b = "100" }

    a { ['b'] = "100" }

    a { [b] = "100" } (```)

    请问这三个表里面的 b 项有什么区别 语言是 Lua 求大佬用门外汉能听懂的说法科普一下

    2 replies  •  2020-05-18 14:32:11 +08:00
    Mutoo
    Mutoo
    May 18, 2020❤️1
    1
    前两个 table 等价,key 都是字面量 "b"
    第三个 b 是一个变量,生成的 table 里面的 key 为 b 的值,value 为 100
    例如
    当 b = "foo"
    则 { [b] = 100 } 为 { foo = 100 }
    Nausicaa
    Nausicaa
    OP
    May 18, 2020
    2
    @Mutoo #1 非常感谢 ❤
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2435 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 12:33 · PVG 20:33 · LAX 04:33 · JFK 07:33
    ♥ Do have faith in what you're doing.