0

我正在尝试在我的 premake5 脚本中添加一个新的 premake5 字段,但无法理解如何指定 field.kind 。

我想添加一个包含 (path, string) 对列表的字段,但不知道如何指定种类 spec 。文档和示例不是特别清楚。

这就是我注册新领域的方式

premake.api.register(   {
        name = "mypathmappings",
        scope = "config",
        kind = "list:path:string",   or "list:keyed:path:string" 
    }
)

在配置范围内,我像这样声明字段项

project myproject
    mypathmappings { ["path/to/file1"] = "stringvalue1", ["path/to/file2"] = "stringvalue2"}

但是,在处理时间方面,我没有得到我在该领域的期望:

function processpathmappings(cfg)
    local pathmappings = cfg.mypathmappings
    for path, value in pairs(pathmappings) do
        --do something with the path and value but
        --value is not a string as expected
     end
end

有人可以解释如何从 api.lua 中注册的字段种类正确构建复杂种类吗?

我知道“list:integer”指定了一个整数列表,但不知道“keyed”元素是如何工作的。

4

1 回答 1

1

目前,无法控制键值中键的“种类”。在当前系统中你能得到的最好的结果是 kind="keyed:string",它应该给你你想要的值(字符串),但是 Premake 不会处理路径(绝对的,等等。 )

如果可行,您可能希望将其翻转为 kind="keyed:path" 并设置如下值:

mypathmappings { ["stringvalue1"] = "path/to/file1" }

但这依赖于您的字符串值在地图中是唯一的。

理论上,Premake 的字段 API 可以扩展为支持各种键;随时打开票证或提交拉取请求。

于 2015-05-26T13:27:51.937 回答