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

有 Lua 大佬在么,问个低端问题。

  •  
  •   MajestySolor · 2022-06-09 20:05:41 +08:00 · 1230 次点击
    这是一个创建于 710 天前的主题,其中的信息可能已经有所发展或是发生改变。

    关于使用table.insert向表里插入新值的方法

    正常情况下比如有这样一个表

    local list = {apple, banana, peach}
    

    然后插入,这样的我懂

    table.insert(list, "grapes"}
    

    但是假如有这样一个表

    local list = {
    	["apple"] = true,
    	["banana"] = true,
    	["peach"] = true,
    }
    

    应该如何使用table.insert插入以下内容?

    "grapes" = true
    
    3 条回复    2022-06-09 20:37:24 +08:00
    Joey2022
        1
    Joey2022  
       2022-06-09 20:12:52 +08:00   ❤️ 1
    list.grapes = true
    changnet
        2
    changnet  
       2022-06-09 20:24:53 +08:00   ❤️ 1
    list.grapes = true 或者 list["grapes"] = true
    MajestySolor
        3
    MajestySolor  
    OP
       2022-06-09 20:37:24 +08:00
    @Joey2022 @changnet 感谢两位
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5389 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 01:49 · PVG 09:49 · LAX 18:49 · JFK 21:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.