luamarmaladezerobranemarmalade-quick

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


I started using Project / Analyze in ZeroBrane Studio for a Marmalade Quick project and i find it quite useful getting me straight on global vs local scopes.

Here is an annoyance though: it points at the libraries - basically - as undefined globals:

.../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'

Is there a way to suppress the warnings for the libraries (or for particular variable names)?

As partial step I started putting this in the file beginning - it doesn't solve the complaints, just lifts them on top:

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

BTW any idea if this affects performance? It seems i am converting global director to a local director, which in theory is faster...


Solution

  • I don't have a way to turn the warnings off on particular variables at the moment, but there is a workaround you can use to suppress the warnings. Instead of local director = director, you can use local director = _G.director or local director = rawget(_G, "director").

    In terms of the faster access, yes using locals is faster than table access (see page 3 of 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, which may change the performance impact.