---
name: "libmawk_get_var"
section: "3libmawk"
platform: "linux"
package: "libmawk1t64"
version: "1.0.4-4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/libmawk_get_var"
---

# libmawk\_get\_var(3libmawk)

returns a pointer to a mawk variable

## NAME

libmawk\_get\_var - returns a pointer to a mawk variable

## SYNOPSIS

```
#include <libmawk.h>

const 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 or modified. Function libmawk\_print\_cell may be used for converting the cell to string.

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).
