1LIBMAWK_REGISTER_FUNCTION(3libmawlki)bmawk manuLaIlBMAWK_REGISTER_FUNCTION(3libmawk)
2
3
4
6 libmawk_register_function - registers a C function with a callback
7
9 #include <libmawk.h>
10
11 typedef CELL *libmawk_c_function(mawk_state_t *m, CELL *sp, int a_args);
12 int libmawk_register_function(mawk_state_t *MAWK, const char *fname,
13 libmawk_c_function *callback);
14 CELL *libmawk_stackret(CELL *original_sp);
15
16
18 The libmawk_register_function() call registers an user defined function
19 donated by the host application in a mawk context so that it acts
20 exactly like user defined functions in written in awk. The name of the
21 new function is given in fname and should not match any of the user
22 defined function names in the awk script.
23
24 When the user function is called back, argument sp is the stack pointer
25 and a_args holds the number of arguments. The user function is respon‐
26 sible for managing the stack: it should pop all arguments before
27 returning.
28
29 The user function should also generate a return value, which is done by
30 calling libmawk_set_cell() on the stack slot returned by libmawk_stack‐
31 ret. Libmawk_stackret should be called with the modified sp after pop‐
32 ping all arguments.
33
34 Argument m is a libmawk context previously returned by libmawk_initial‐
35 ize() or libmawk_initialize_stage3().
36
37 For more information about user function callbacks, especially on stack
38 handling, see manual page example(3libmawk).
39
41 The user function should return the stack pointer after popping all
42 arguments.
43
44 The libmawk_register_function call returns 0 on success.
45
46 Call libmawk_stackret returns a stack pointer to the slot where the
47 user function should store its return value.
48
49
51 libmawk_initialize_stage(3libmawk), libmawk_initialize(3libmawk), lib‐
52 mawk_set_cell(3libmawk), libmawk_print_cell(3libmawk).
53
54
55
56
57
58libmawk 2009-08-12LIBMAWK_REGISTER_FUNCTION(3libmawk)