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

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

  •  
  •   Nausicaa · May 18, 2020 · 2368 views
    This topic created in 2205 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
        1
    Mutoo  
       May 18, 2020   ❤️ 1
    前两个 table 等价,key 都是字面量 "b"
    第三个 b 是一个变量,生成的 table 里面的 key 为 b 的值,value 为 100
    例如
    当 b = "foo"
    则 { [b] = 100 } 为 { foo = 100 }
    Nausicaa
        2
    Nausicaa  
    OP
       May 18, 2020
    @Mutoo #1 非常感谢 ❤
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3290 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 14:05 · PVG 22:05 · LAX 07:05 · JFK 10:05
    ♥ Do have faith in what you're doing.