ZeroBrane 的分析:"unknown global variable" 库对象

ZeroBrane's Analyze: "unknown global variable" on library objects

我开始在 ZeroBrane Studio 中使用 Project / Analyze 进行 Marmalade Quick 项目,我发现它非常有用,可以让我直接了解全球和本地范围。

这里有一个烦恼:它指向库 - 基本上 - 作为未定义的全局变量:

.../resources/main.lua(11): first use of unknown global variable 'system'
.../resources/main.lua(12): first use of unknown global variable 'json'
.../resources/main.lua(13): first use of unknown global variable 'device'
.../resources/main.lua(14): first use of unknown global variable 'physics'
.../resources/main.lua(15): first use of unknown global variable 'color'
.../resources/main.lua(16): first use of unknown global variable 'director'
.../resources/main.lua(17): first use of unknown global variable 'key'

有没有办法抑制库(或特定变量名)的警告?

作为部分步骤,我开始将其放在文件开头 - 它并没有解决投诉,只是将它们提升到顶部:

local system = system
local json = json
local device = device
local physics = physics
local color = color
local director = director
local key = key

顺便说一句,知道这是否会影响性能吗?看来我正在将全局 director 转换为本地 director,这在理论上更快...

目前我没有办法关闭特定变量的警告,但是有一个解决方法可以用来抑制警告。您可以使用 local director = _G.directorlocal director = rawget(_G, "director").

而不是 local director = director

就更快的访问而言,是的,使用 locals 比 table 访问更快(参见 Lua performance tips), but you likely need to run a large number of calls in a loop to see the difference. Note that LuaJIT does its own optimization 的第 3 页,这可能会改变性能影响。