Atom Packages Directory

a package directory for a text editor of the 21st Century

Linter Lua Findglobals

Install with:
    apm install linter-lua-findglobals


Check Lua files for global variable access on the fly. Based on the FindGlobals lua script by Mikk.

Due to the way that luac works, global variables will only be highlighted while there is not an error found in the file.


Before using this package, you must ensure that you have luac or luajit installed on your system. If the program is not available on your system path, you will need to set the path in settings:

File -> Settings -> Packages -> Linter Lua Findglobals -> Luac

See for more information about luac.

What do I need to know about globals for?

To optimize performance, you may want to declare local versions of commonly used functions and variables rather than make global namespace lookups.

Some global variables you may be okay with being global accesses (or in fact NEED them to because they can be hooked or changed), for those you have two options:

  1. Add one or more -- GLOBALS: SomeFunc, SomeOtherFunc, SomeGlobalVariable lines to the source file. This will ignore the variables.
  2. Put a local _G = _G at the top of the file, and then access them through _G.SomeFunc. This is actually somewhat faster than accessing them directly, believe it or not. Direct global access involves looking up the global variable table first!

Another benefit is finding the odd misspelled variable name or blocks of code that you may have copy/pasted from another source but forgot to update variables used.

Directives in the file

You can change how the linter reports for a file. These directives can be anywhere in the file and will take effect globally.

– GLOBALS: SomeGlobal, SomeOtherGlobal - The linter will never complain about these, but there is no way to un-GLOBAL an already declared global. There may be multiple of these anywhere in the file.

– GETGLOBALFILE [ON|OFF] - Enable/disable GETGLOBAL checks in the global scope. (Default: OFF)

– GETGLOBALFUNC [ON|OFF] - Enable/disable GETGLOBAL checks in functions. (Default: ON)

– SETGLOBALFILE [ON|OFF] - Enable/disable SETGLOBAL checks in the global scope. (Default: ON)

– SETGLOBALFUNC [ON|OFF] - Enable/disable SETGLOBAL checks in functions. (Default: ON)


Keywords: linter, lua Suggest keywords
Fork me on GitHub