Variables

Far Manager Macro System

Variables


Macrofile environment variables

Macros that are loaded from the same file share a common environment table. The variables declared without the local keyword belong to that environment.

  Example: var = 15

The macrofile’s environment variables keep their values unchanged between macro calls. Their values are reset to initial state upon execution of any macro loading operation: Far Manager start, macro:load, lm:load, far.MacroLoadAll, MacroControl(MCTL_LOADALL).

Global variables

To set global variables, whose values are stored during the whole Far Manager session and are accessible from any script, one should use the _G table.

  Example: _G.var = 15

Global variables do not change their values even when macros are reloaded, except for Far Manager restart or LuaMacro plugin reload.

When reading a non-existent environment variable, a same-named global variable can be read instead.

  Example:
    var = 5
    _G.var = 10
    far.Message(var) --> 5
    var = nil
    far.Message(var) --> 10

Upvalues

Top-level local variables accessible from functions of one or several macros (upvalues) keep their values unchanged between macro calls. Their values are reset upon execution of any macro loading operation.

  Example:
    local var = 15
    function inc_var() var = var+1 end
    function dec_var() var = var-1 end