WSTestHead (C Function)
int WSTestHead(WSLINK link,const char *head,int *n)
tests that the next object to be read from link is an expression with head head, and stores the number of arguments of the expression in n.
Details
- WSTestHead() fails if the current object on the link is not a function with a symbol as a head, or if the name of the symbol does not match head.
- WSTestHead() returns 0 in the event of an error, and a nonzero value if the function succeeds.
- Use WSError() to retrieve the error code if WSTestHead() fails.
- WSTestHead() will reset the stream pointer to the expression on the link just prior to calling WSTestHead() if the function fails. This operation behaves as if the programmer called WSCreateMark(link); WSTestHead(…); WSSeekToMark(…).
- WSTestHead() is declared in the WSTP header file wstp.h.
Examples
Basic Examples (1)
#include "wstp.h"
/* test whether the head of the incoming object is "ReturnPacket" */
void f(WSLINK lp)
{
int args;
if(WSTestHead(lp, "ReturnPacket", &args))
{ /* read the contents of the ReturnPacket[] */ }
else
{ /* the head of incoming packet is not "ReturnPacket" */ }
}