LIBMAWK_GET_VAR(3libmawk)

πŸ’– LIBMAWK_GET_VAR(3libmawk) πŸ’–

okay bestie, welcome to the libmawk manual β€” yes we're doing C library lore today and honestly? it's giving iconic. sit down, grab a strawberry, we're getting 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);

like yes, two functions, one header, we love a duo πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so. libmawk_get_var() hands you back a pointer to a mawk cell that represents the global variable whose name you dropped in vname, inside the context you passed in. that's it, that's the whole vibe.

⚠️ okay this part is IMPORTANT bestie β€” the CELL you get back should never be free'd, destroyed, or modified. not even a little. hands off. it's not yours, it's the library's πŸ’€

and if you're like "ok but how do i even look at it", the function libmawk_print_cell may be used for converting the cell to a string ✨


🌈 libmawk_get_array_at() β€” the array girlie 🌈

libmawk_get_array_at() does the exact same operation, but for an element of an array instead of a plain global.

  • it returns -1 if arr_name is not an array, or if anything goes wrong (error city 😭)
  • if idx is not an existing index in the array, it gets allocated β€” but only if alloc is non-zero. so like, alloc = "go ahead, make it exist"
  • if res is not NULL, it gets destroyed β€” regardless of the return value, no takebacks β€” and then, if the index exists (or was just created by this very call), it's loaded with the value
  • the caller needs to destroy res after use. that's on you, not on the library
  • and because res gets destroyed whenever it's non-NULL, it must be a valid cell with a valid type. no half-baked cells, periodt πŸ‘‘

πŸ’œ about that m argument

argument m is a libmawk context that was previously returned by libmawk_initialize() or libmawk_initialize_stage3(). so don't just make one up, get it from those first, iykyk 🧚


⭐ SEE ALSO ⭐


and that's the whole page, bestie, you ate πŸ’… this was libmawk, dated 2009-08-12, from the LIBMAWK_GET_VAR(3libmawk) era β€” vintage but still slaying πŸ‘‘πŸ’–