premake5 添加新的复杂字段
premake5 adding new complex fields
我正在尝试在我的 premake5 脚本中添加一个新的 premake5 字段,但我无法理解如何指定 field.kind 。
我想添加一个包含(路径,字符串)对列表的字段,但不知道如何指定种类规范。
文档和例子都不是特别清楚
这就是我注册新领域的方式
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" 元素是如何工作的。
目前无法控制键控值中键的 "kind"。当前系统能得到的最好的是 kind="keyed:string",它应该给你你想要的值(字符串),但路径不会被 Premake 处理(绝对化等)。 )
如果可行,您可能希望将其翻转为 kind="keyed:path" 并像这样设置值:
mypathmappings { ["stringvalue1"] = "path/to/file1" }
但这取决于您的字符串值在地图中是唯一的。
理论上,Premake 的字段 API 可以扩展以支持各种密钥;欢迎 open a ticket 或提交拉取请求。
我正在尝试在我的 premake5 脚本中添加一个新的 premake5 字段,但我无法理解如何指定 field.kind 。
我想添加一个包含(路径,字符串)对列表的字段,但不知道如何指定种类规范。 文档和例子都不是特别清楚
这就是我注册新领域的方式
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" 元素是如何工作的。
目前无法控制键控值中键的 "kind"。当前系统能得到的最好的是 kind="keyed:string",它应该给你你想要的值(字符串),但路径不会被 Premake 处理(绝对化等)。 )
如果可行,您可能希望将其翻转为 kind="keyed:path" 并像这样设置值:
mypathmappings { ["stringvalue1"] = "path/to/file1" }
但这取决于您的字符串值在地图中是唯一的。
理论上,Premake 的字段 API 可以扩展以支持各种密钥;欢迎 open a ticket 或提交拉取请求。