Package list libmawk / scrub-obsolete/main doc / libmawk_register_function.3libmawk.html
scrub-obsolete/main

Tree @scrub-obsolete/main (Download .tar.gz)

libmawk_register_function.3libmawk.html @scrub-obsolete/mainraw · history · blame

<!-- Creator     : groff version 1.22.2 -->
<!-- CreationDate: Sat Jun 14 14:27:32 2014 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
       p       { margin-top: 0; margin-bottom: 0; vertical-align: top }
       pre     { margin-top: 0; margin-bottom: 0; vertical-align: top }
       table   { margin-top: 0; margin-bottom: 0; vertical-align: top }
       h1      { text-align: center }
</style>
<title>LIBMAWK_REGISTER_FUNCTION</title>

</head>
<body>

<h1 align="center">LIBMAWK_REGISTER_FUNCTION</h1>

<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>

<hr>


<h2>NAME
<a name="NAME"></a>
</h2>



<p style="margin-left:11%; margin-top: 1em">libmawk_register_function
&minus; registers a C function with a callback</p>

<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>


<p style="margin-left:11%; margin-top: 1em"><b>#include
&lt;libmawk.h&gt;</b></p>

<p style="margin-left:11%; margin-top: 1em"><b>typedef CELL
*libmawk_c_function(mawk_state_t *</b><i>m</i><b>, CELL
*</b><i>sp</i><b>, int</b> <i>a_args</i><b>); <br>
int libmawk_register_function(mawk_state_t
*</b><i>MAWK</i><b>, const char *</b><i>fname</i><b>,
libmawk_c_function *</b><i>callback</i><b>); <br>
CELL *libmawk_stackret(CELL
*</b><i>original_sp</i><b>);</b></p>

<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>


<p style="margin-left:11%; margin-top: 1em">The
<b>libmawk_register_function</b>() call registers an user
defined function donated by the host application in a mawk
context so that it acts exactly like user defined functions
in written in awk. The name of the new function is given in
<i>fname</i> and should not match any of the user defined
function names in the awk script.</p>

<p style="margin-left:11%; margin-top: 1em">When the user
function is called back, argument <i>sp</i> is the stack
pointer and <i>a_args</i> holds the number of arguments. The
user function is responsible for managing the stack: it
should pop all arguments before returning.</p>

<p style="margin-left:11%; margin-top: 1em">The user
function should also generate a return value, which is done
by calling libmawk_set_cell() on the stack slot returned by
libmawk_stackret. Libmawk_stackret should be called with the
modified <i>sp</i> after popping all arguments.</p>

<p style="margin-left:11%; margin-top: 1em">Argument m is a
libmawk context previously returned by libmawk_initialize()
or libmawk_initialize_stage3().</p>

<p style="margin-left:11%; margin-top: 1em">For more
information about user function callbacks, especially on
stack handling, see manual page example(3libmawk).</p>

<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>


<p style="margin-left:11%; margin-top: 1em">The user
function should return the stack pointer after popping all
arguments.</p>

<p style="margin-left:11%; margin-top: 1em">The
libmawk_register_function call returns 0 on success.</p>

<p style="margin-left:11%; margin-top: 1em">Call
libmawk_stackret returns a stack pointer to the slot where
the user function should store its return value.</p>

<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>



<p style="margin-left:11%; margin-top: 1em"><b>libmawk_initialize_stage</b>(3libmawk),
<b>libmawk_initialize</b>(3libmawk),
<b>libmawk_set_cell</b>(3libmawk),
<b>libmawk_print_cell</b>(3libmawk).</p>
<hr>
</body>
</html>