【问题标题】:ZeroBrane's Analyze: "unknown global variable" on library objectsZeroBrane 的分析:库对象上的“未知全局变量”
【发布时间】:2015-04-05 22:53:13
【问题描述】:

我开始在 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,理论上更快...

【问题讨论】:

    标签: lua marmalade zerobrane marmalade-quick


    【解决方案1】:

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

    就更快的访问而言,是的,使用本地比访问表更快(参见Lua performance tips 的第 3 页),但您可能需要在循环中运行大量调用才能看到差异。请注意,LuaJIT 执行its own optimization,这可能会改变性能影响。

    【讨论】:

    • 不知道_G,谢谢! _G. 技巧对我很有用。 IE。我会在开始时做local director = G_.director 等等,这会处理这些投诉,现在我可以只关注我的变量。我会将其视为我和分析器之间的“导入”样板合同:)
    猜你喜欢
    • 1970-01-01
    • 2019-08-26
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多