LIBMAWK_CALL_FUNCTION(3libmawk)
π LIBMAWK_CALL_FUNCTION β bestie edition π
okay so this is from the libmawk manual, and we're talking about calling your own awk functions from C. no cap, it's giving β¨bridgesβ¨. sit down, hydrate, let's go π«Ά
β¨ NAME β¨
libmawk_call_function β call an user defined (script) function πΈ
β¨ SYNOPSIS β¨
#include <libmawk.h>
int libmawk_call_function(mawk_state_t *MAWK, const char *fname, CELL *res, const char *argtpes, ...);
int libmawk_call_functionp(mawk_state_t *MAWK, const char *fname, CELL *res, const char *argtpes, void **args);
β¨ DESCRIPTION β¨
so like, the whole vibe here is: you've written some awk function in a script, and now your C program is like "hey. run that for me." iconic behavior honestly π
libmawk_call_function() goes and looks up an user defined awk function called fname, fills the stack with arguments converted from the varargs, and then calls the function. that's it. that's the whole thing. slay.
libmawk_call_functionp() does the exact same action but it avoids using vararg by requiring an array of generic pointers to the function arguments. so if you're the type who hates varargs (valid), this one's your girl π
Argtype is a zero terminated string for both functions, bestie β each character corresponds to an argument. Type characters are described in libmawk_set_cell() manual page. go read that one, it's the lore iykyk π
β οΈ now pay attention because this part is important: if res is non-NULL, it iscell_destroyed(regardless of errors β yes, even if things go sideways π) and the return value of the user function is copied into it. The caller shall runlibmawk_cell_destroyon it. don't forget. don't be that person. π«Ά
Argument m is a libmawk context previously returned by libmawk_initialize() or libmawk_initialize_stage3(). gotta have your context, no context no function call, periodt. π
β¨ RETURN VALUE β¨
A pointer to the cell returned by the user function. π₯
The cell returned must be destroyed by the application using libmawk_cell_destroy. like, actually. the way that memory is just sitting there waiting for you to clean it upβ¦ main character energy but for leaks π
β¨ SEE ALSO β¨
libmawk_initialize_stage(3libmawk)libmawk_initialize(3libmawk)libmawk_cell_destroy(3libmawk)libmawk_set_cell(3libmawk)
okay that's the whole page bestie, you ate it up fr fr π
libmawk Β· 2009-08-10 Β· LIBMAWK_CALL_FUNCTION(3libmawk) πβ¨π¦
mwah, go call some functions π
π¦ where this page comes from
- debian bookworm: libmawk1 1.0.2-3
- debian trixie: libmawk1t64 1.0.4-4
- fedora 43: libmawk-devel 1.0.3-8.fc41 Β· GPLv2
- fedora 43: libmawk-devel 1.0.3-8.fc41 Β· GPLv2
- fedora 44: libmawk-devel 1.0.5-1.fc44 Β· GPL-2.0-only
- fedora 44: libmawk-devel 1.0.5-1.fc44 Β· GPL-2.0-only
- ubuntu jammy: libmawk1 1.0.2-3
- ubuntu noble: libmawk1t64 1.0.4-3build1
- ubuntu questing: libmawk1t64 1.0.4-5
- ubuntu resolute: libmawk1t64 1.0.5-1
- ubuntu stonking: libmawk1t64 1.0.5-1
- Copyright 2009 Tibor Palinkas (mawk@inno.bme.hu)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms