Next: , Previous: , Up: preprocessor nameref   [Contents][Index]


2.7.2 Full NAMEREF declarations

When defining array variables we must use the specific macros, rather than the ones below; Special NAMEREF declarations.

Preprocessor Macro: mbfl_local_varref (NAME, INIT_VALUE, LOCAL_OPTIONS)

Expands into:

local mbfl_a_variable_NAME
mbfl_variable_alloc mbfl_a_variable_NAME
local LOCAL_OPTIONS $mbfl_a_variable_NAME
local -n NAME=$mbfl_a_variable_NAME

and when INIT_VALUE is not empty, it finishes with:

NAME=INIT_VALUE

A local name variable mbfl_a_variable_NAME is declared and filled with a unique data variable name by mbfl_variable_alloc(); then the data variable is declared as local; finally a proxy variable NAME is defined as alias for the data variable.

The data variable is given the LOCAL_OPTIONS.

Preprocessor Macro: mbfl_global_varref (NAME, INIT_VALUE, DECLARE_OPTIONS)

Expands into:

local mbfl_a_variable_NAME
mbfl_variable_alloc mbfl_a_variable_NAME
declare -g DECLARE_OPTIONS $mbfl_a_variable_NAME
local -n NAME=$mbfl_a_variable_NAME

and when INIT_VALUE is not empty, it finishes with:

NAME=INIT_VALUE

A local name variable mbfl_a_variable_NAME is declared and filled with a unique data variable name by mbfl_variable_alloc(); then the data variable is declared as global; finally a proxy variable NAME is defined as alias for the data variable.

The data variable is given the DECLARE_OPTIONS.

When we have finished using a global varref set of variables, we must unset the global data variable; we can do it as follows:

function main () {
    mbfl_global_varref(VAR)

    mbfl_location_enter
    {
        mbfl_location_handler "unset -v mbfl_datavar(VAR)"

        # Do something here with VAR.
        ...
    }
    mbfl_location_leave
}

Next: , Previous: , Up: preprocessor nameref   [Contents][Index]

This document describes version 3.0.0-devel.0 of Marcos Bash Functions Library.