You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Premake.lua执行报错:nil值索引及后续相关问题求助

问题解决

第一个报错:attempt to index a nil value

你的代码里filter语句存在语法错误,这是导致该报错的核心原因。Premake中filter是函数调用,不能在语句末尾加冒号,正确写法是用空格分隔,后续配置项通过缩进表示作用域:

修正后的Windows平台配置代码:

34  filter "system:windows"
35      cppdialect "C++17"
36      staticruntime "On"
37      systemversion "latest"

同样,Debug配置的filter语句也需要去掉末尾冒号:

49  filter "configurations:Debug"
50      defines "BZ_DEBUG"
51      symbols "On"

第二个报错:attempt to perform arithmetic on a table value (global 'cfg')

这个错误是因为脚本中某处把访问表字段的正确写法cfg.architecture写成了cfg-architecture——减号会被Premake识别为算术减法运算符,而cfg是表类型,无法参与算术运算。全局搜索你的premake.lua文件,找到所有类似cfg-xxx的错误写法,替换为cfg.xxx即可解决。

内容的提问来源于stack exchange,提问作者Bjørn Pollen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 13:04:55