Seth Woolley's Man Viewer

Tcl_CreateMathFunc(3) - Tcl_CreateMathFunc, Tcl_GetMathFuncInfo, Tcl_ListMathFuncs - Define, query and enumerate math functions for expressions - man 3 Tcl_CreateMathFunc

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

Tcl_CreateMathFunc(3)       Tcl Library Procedures       Tcl_CreateMathFunc(3)



______________________________________________________________________________

NAME
       Tcl_CreateMathFunc,  Tcl_GetMathFuncInfo,  Tcl_ListMathFuncs  - Define,
       query and enumerate math functions for expressions

SYNOPSIS
       #include <tcl.h>

       void
       Tcl_CreateMathFunc(interp, name, numArgs, argTypes, proc(5,n), clientData)

       int                                                                     |
       Tcl_GetMathFuncInfo(interp, name, numArgsPtr, argTypesPtr, procPtr, clientDataPtr)|

       Tcl_Obj *                                                               |
       Tcl_ListMathFuncs(interp, pattern)                                      |

ARGUMENTS
       Tcl_Interp      *interp          (in(1,8))      Interpreter  in(1,8)  which   new
                                                  function will be defined.    |

       CONST                                                                   |
       char      *name            (in(1,8))                                   |     |
                                                  Name for new function.

       int             numArgs          (in(1,8))      Number of arguments  to  new
                                                  function;   also  gives size
                                                  of argTypes array.

       Tcl_ValueType   *argTypes        (in(1,8))      Points to  an  array  giving
                                                  the  permissible  types  for
                                                  each argument to function.

       Tcl_MathProc    *proc(5,n)            (in(1,8))      Procedure  that   implements
                                                  the function.

       ClientData      clientData       (in(1,8))      Arbitrary  one-word value to
                                                  pass  to  proc(5,n)  when  it  is
                                                  invoked.

       int             *numArgsPtr      (out)     Points  to  a  variable that
                                                  will be set(7,n,1 builtins) to  contain  the
                                                  number  of  arguments to the
                                                  function.

       Tcl_ValueType   **argTypesPtr    (out)     Points to  a  variable  that
                                                  will  be  set(7,n,1 builtins)  to  contain a
                                                  pointer to an  array  giving
                                                  the  permissible  types  for
                                                  each argument to  the  func-
                                                  tion  which  will need to be
                                                  freed up using Tcl_Free.

       Tcl_MathProc    **procPtr        (out)     Points to  a  variable  that
                                                  will  be  set(7,n,1 builtins)  to  contain a
                                                  pointer to  the  implementa-
                                                  tion  code  for the function
                                                  (or NULL if(3,n) the function  is
                                                  implemented    directly   in(1,8)
                                                  bytecode.)

       ClientData      *clientDataPtr   (out)     Points to  a  variable  that
                                                  will  be  set(7,n,1 builtins) to contain the
                                                  clientData  argument  passed
                                                  to  Tcl_CreateMathFunc  when
                                                  the function was created  if(3,n)
                                                  the  function  is not imple-
                                                  mented directly in(1,8) bytecode.

       CONST char      *pattern         (in(1,8))      Pattern   to  match  against
                                                  function names so as to fil-
                                                  ter(1,3x,3x curs_util)   them  (by  passing  to
                                                  Tcl_StringMatch), or NULL to
                                                  not apply any filter.
_________________________________________________________________


DESCRIPTION
       Tcl  allows  a  number  of mathematical functions to be used in(1,8) expres-
       sions, such as sin, cos, and hypot.  Tcl_CreateMathFunc allows applica-
       tions  to  add additional functions to those already provided by Tcl or
       to replace existing functions.  Name is the name of the function as  it
       will  appear  in(1,8) expressions.  If name doesn't already exist as a func-
       tion then a new function is created.  If it does exist, then the exist-
       ing  function is replaced.  NumArgs and argTypes describe the arguments
       to the function.  Each entry in(1,8) the  argTypes  array  must  be  one  of |
       TCL_INT,  TCL_DOUBLE,  TCL_WIDE_INT,  or TCL_EITHER to indicate whether |
       the corresponding argument  must  be  an  integer,  a  double-precision |
       floating value, a wide (64-bit) integer, or any, respectively.

       Whenever the function is invoked in(1,8) an expression Tcl will invoke proc(5,n).
       Proc should have arguments and result that match the type Tcl_MathProc:
              typedef int Tcl_MathProc(
                ClientData clientData,
                Tcl_Interp *interp,
                Tcl_Value *args,
                Tcl_Value *resultPtr);

       When  proc(5,n)  is  invoked the clientData and interp arguments will be the
       same as those passed to Tcl_CreateMathFunc.   Args  will  point  to  an
       array  of numArgs Tcl_Value structures, which describe the actual argu-
       ments to the function:                                                  |
              typedef struct Tcl_Value {                                       |
                Tcl_ValueType type;                                            |
                long intValue;                                                 |
                double doubleValue;                                            |
                Tcl_WideInt wideValue;                                         |
              } Tcl_Value;                                                     |

       The type field indicates the  type  of  the  argument  and  is  one  of |
       TCL_INT,  TCL_DOUBLE or TCL_WIDE_INT.  It will match the argTypes value
       specified for the function unless the argTypes  value  was  TCL_EITHER.
       Tcl  converts  the  argument  supplied  in(1,8)  the  expression to the type
       requested in(1,8) argTypes, if(3,n) that is necessary.  Depending on the value of
       the  type field, the intValue, doubleValue or wideValue field will con- |
       tain the actual value of the argument.

       Proc should compute its result and store it either  as  an  integer  in(1,8)
       resultPtr->intValue  or  as a floating value in(1,8) resultPtr->doubleValue.
       It should set(7,n,1 builtins) also resultPtr->type to one  of  TCL_INT,  TCL_DOUBLE  or |
       TCL_WIDE_INT  to  indicate  which  value was set.  Under normal circum-
       stances proc(5,n) should return TCL_OK.  If an error(8,n) occurs while  executing
       the  function,  proc(5,n) should return TCL_ERROR and leave an error(8,n) message
       in(1,8) the interpreter's result.

       Tcl_GetMathFuncInfo retrieves the values associated with function  name |
       that were passed to a preceding Tcl_CreateMathFunc call.  Normally, the |
       return code is TCL_OK  but  if(3,n)  the  named(5,8)  function  does  not  exist, |
       TCL_ERROR  is  returned  and  an  error(8,n) message is placed in(1,8) the inter- |
       preter's result.                                                        |

       If an error(8,n) did not occur, the array reference placed in(1,8)  the  variable |
       pointed to by argTypesPtr is newly allocated, and should be released by |
       passing it to Tcl_Free.  Some functions (the standard  set(7,n,1 builtins)  implemented |
       in(1,8) the core) are implemented directly at the bytecode level; attempting |
       to retrieve values for them causes a NULL to be stored in(1,8) the  variable |
       pointed to by procPtr and the variable pointed to by clientDataPtr will |
       not be modified.                                                        |

       Tcl_ListMathFuncs returns a Tcl object containing a  list  of  all  the |
       math  functions  defined in(1,8) the interpreter whose name matches pattern. |
       In the case of an error(8,n), NULL is returned and an error(8,n) message is  left |
       in(1,8)  the interpreter result, and otherwise the returned object will have |
       a reference count of zero.


KEYWORDS
       expression, mathematical function


SEE ALSO
       expr(1,3,n)(n), info(1,5,n)(n), Tcl_Free(3), Tcl_NewListObj(3)



Tcl                                   8.4                Tcl_CreateMathFunc(3)

References for this manual (incoming links)