# LIBMAWK_GET_VAR

NAME
SYNOPSIS
DESCRIPTION
SEE ALSO

## NAME

libmawk_get_var − returns a pointer to a mawk variable

## SYNOPSIS

#include <libmawk.h>

CELL *libmawk_get_var(mawk_state_t *m, const char *vname);
int libmawk_get_array_at(mawk_state_t *m, const char *arr_name,
const char *idx, const char *res, int alloc);

## DESCRIPTION

The libmawk_get_var() function returns a pointer to a mawk cell that represents the global variable with name passed in vname in the given context. The returned CELL should never be free’d or destroyed. Function libmawk_print_cell may be used for converting the cell to string. The caller should not change the type of cell but is free to change the value.

Function libmawk_get_array_at() performs the same operation for an element of an array. -1 is returned if arr_name is not an array or upon an error. If idx is not an existing index in the array it is allocated if alloc is non-zero. If res is not NULL, it is destroyed (regardless of the return value) and if the index exists (or is created by the call), is loaded with the value. The caller needs to destroy res after use. Since res is destroyed when non-NULL, it must be a valid cell with valid type.

Argument m is a libmawk context previously returned by libmawk_initialize() or libmawk_initialize_stage3().

## SEE ALSO

libmawk_initialize_stage(3libmawk), libmawk_initialize(3libmawk), libmawk_call_function(3libmawk), libmawk_print_cell(3libmawk).