如何在Lua中从表格中检索另一个变量?

3

如何在shortdesc中使用title

以下方法会失败:

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

4
您不能这样做;但是您可以使用本地变量:
function descriptor()
    local title = "This"
    return {
        title = title;
        shortdesc = title .. " is my text."
    }
end

4

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接