【问题标题】:How to retrieve another variable within table in Lua?如何在 Lua 的表中检索另一个变量?
【发布时间】:2015-03-31 05:26:51
【问题描述】:

如何在shortdesc 中使用title

这失败了:

function descriptor()
    return {
        title = "This";
        shortdesc = title .. " is my text."
    }
end

【问题讨论】:

    标签: function variables lua return lua-table


    【解决方案1】:

    你不能;你可以使用局部变量:

    function descriptor()
        local title = "This"
        return {
            title = title;
            shortdesc = title .. " is my text."
        }
    end
    

    【讨论】:

      【解决方案2】:

      保罗是正确的。您也可以分段构建表格:

      function descriptor()
          local t = {}
          t.title = "This";
          t.shortdesc = t.title .. " is my text."
          return t
      end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-23
        • 2021-09-07
        • 1970-01-01
        • 1970-01-01
        • 2017-05-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多