gretl_func

gretl_func —

Synopsis

enum                FuncDataReq;
#define             NEEDS_TS
#define             NEEDS_QM
#define             NEEDS_PANEL
#define             NO_DATA_OK
#define             FN_NAMELEN
typedef             ufunc;
typedef             fnpkg;
typedef             fnargs;
int                 n_free_functions                    (void);
ufunc *             get_user_function_by_name           (const char *name);
const ufunc *       get_user_function_by_index          (int idx);
int                 fn_n_params                         (const ufunc *fun);
int                 fn_param_type                       (const ufunc *fun,
                                                         int i);
const char *        fn_param_name                       (const ufunc *fun,
                                                         int i);
const char *        fn_param_descrip                    (const ufunc *fun,
                                                         int i);
double              fn_param_default                    (const ufunc *fun,
                                                         int i);
double              fn_param_minval                     (const ufunc *fun,
                                                         int i);
double              fn_param_maxval                     (const ufunc *fun,
                                                         int i);
int                 fn_param_optional                   (const ufunc *fun,
                                                         int i);
int                 user_func_get_return_type           (const ufunc *fun);
const char *        user_function_name_by_index         (int i);
int                 user_function_index_by_name         (const char *name,
                                                         fnpkg *pkg);
int                 user_function_set_debug             (const char *name,
                                                         int debug);
void                function_names_init                 (void);
const char *        next_available_function_name        (int *idxp);
int                 gretl_compiling_function            (void);
int                 gretl_function_depth                (void);
int                 gretl_start_compiling_function      (const char *line,
                                                         PRN *prn);
int                 gretl_function_append_line          (const char *line);
int                 gretl_is_public_user_function       (const char *name);
int                 gretl_function_exec                 (ufunc *u,
                                                         fnargs *args,
                                                         int rtype,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         void *ret,
                                                         char **descrip,
                                                         PRN *prn);
char *              gretl_func_get_arg_name             (const char *argvar,
                                                         int *err);
int                 object_is_const                     (const char *name);
void                sample_range_get_extrema            (const DATAINFO *pdinfo,
                                                         int *t1,
                                                         int *t2);
const char *        get_funcerr_message                 (void);
int                 function_return_type_from_string    (const char *s);
int                 gretl_function_print_code           (ufunc *u,
                                                         PRN *prn);
fnpkg *             function_package_new                (const char *fname,
                                                         char **pubnames,
                                                         int n_pub,
                                                         char **privnames,
                                                         int n_priv,
                                                         int *err);
int                 function_package_connect_funcs      (fnpkg *pkg,
                                                         char **pubnames,
                                                         int n_pub,
                                                         char **privnames,
                                                         int n_priv);
int                 function_package_set_properties     (fnpkg *pkg,
                                                         ...);
int                 function_package_get_properties     (fnpkg *pkg,
                                                         ...);
const char *        function_package_get_name           (fnpkg *pkg);
int                 function_package_write_file         (fnpkg *pkg);
int                 check_function_needs                (const DATAINFO *pdinfo,
                                                         FuncDataReq dreq,
                                                         int minver);
int                 write_session_functions_file        (const char *fname);
int                 read_session_functions_file         (const char *fname);
fnpkg *             get_function_package_by_filename    (const char *fname);
int                 load_function_package_from_file     (const char *fname);
void                function_package_unload_by_filename (const char *fname);
void                function_package_unload_full_by_filename
                                                        (const char *fname);
int                 print_function_package_info         (const char *fname,
                                                         PRN *prn);
int                 print_function_package_code         (const char *fname,
                                                         PRN *prn);
ufunc *             get_packaged_function_by_name       (const char *name,
                                                         fnpkg *pkg);
int                 get_function_file_header            (const char *fname,
                                                         char **pdesc,
                                                         char **pver);
int                 update_function_from_script         (const char *funname,
                                                         const char *path,
                                                         fnpkg *pkg);
int                 user_function_help                  (const char *fnname,
                                                         PRN *prn);
void                gretl_functions_cleanup             (void);
fnargs *            fn_args_new                         (void);
void                fn_args_free                        (fnargs *args);
int                 push_fn_arg                         (fnargs *args,
                                                         int type,
                                                         void *p);
void                adjust_indent                       (const char *line,
                                                         int *this_indent,
                                                         int *next_indent);

Description

Details

enum FuncDataReq

typedef enum {
    FN_NEEDS_TS = 1, /* function requires time-series data */
    FN_NEEDS_QM,     /* function requires quarterly or monthly data */
    FN_NEEDS_PANEL,  /* function requires panel data */
    FN_NODATA_OK     /* function does not require a dataset */
} FuncDataReq;


NEEDS_TS

#define NEEDS_TS    "needs-time-series-data"


NEEDS_QM

#define NEEDS_QM    "needs-qm-data"


NEEDS_PANEL

#define NEEDS_PANEL "needs-panel-data"


NO_DATA_OK

#define NO_DATA_OK  "no-data-ok"


FN_NAMELEN

#define FN_NAMELEN 32


ufunc

typedef struct ufunc_ ufunc;


fnpkg

typedef struct fnpkg_ fnpkg;


fnargs

typedef struct fnargs_ fnargs;


n_free_functions ()

int                 n_free_functions                    (void);

Returns : the number of functions loaded in memory that are not currently attached to any function package, and are therefore available for packaging.

get_user_function_by_name ()

ufunc *             get_user_function_by_name           (const char *name);

name :
Returns :

get_user_function_by_index ()

const ufunc *       get_user_function_by_index          (int idx);

idx : index number.
Returns : pointer to the user-function that currently occupies (0-based) slot idx in the array of loaded functions, or NULL if idx is out of bounds.

fn_n_params ()

int                 fn_n_params                         (const ufunc *fun);

fun : pointer to user-function.
Returns : the number of parameters associated with fun.

fn_param_type ()

int                 fn_param_type                       (const ufunc *fun,
                                                         int i);

fun : pointer to user-function.
i : 0-based parameter index.
Returns : the type of parameter i of function fun.

fn_param_name ()

const char *        fn_param_name                       (const ufunc *fun,
                                                         int i);

fun : pointer to user-function.
i : 0-based parameter index.
Returns : the name of parameter i of function fun.

fn_param_descrip ()

const char *        fn_param_descrip                    (const ufunc *fun,
                                                         int i);

fun : pointer to user-function.
i : 0-based parameter index.
Returns : the description of parameter i of function fun (if any), otherwise NULL.

fn_param_default ()

double              fn_param_default                    (const ufunc *fun,
                                                         int i);

fun : pointer to user-function.
i : 0-based parameter index.
Returns : the default value of (scalar) parameter i of function fun (if any), otherwise NADBL.

fn_param_minval ()

double              fn_param_minval                     (const ufunc *fun,
                                                         int i);

fun : pointer to user-function.
i : 0-based parameter index.
Returns : the minimum value of (scalar) parameter i of function fun (if any), otherwise NADBL.

fn_param_maxval ()

double              fn_param_maxval                     (const ufunc *fun,
                                                         int i);

fun : pointer to user-function.
i : 0-based parameter index.
Returns : the maximum value of (scalar) parameter i of function fun (if any), otherwise NADBL.

fn_param_optional ()

int                 fn_param_optional                   (const ufunc *fun,
                                                         int i);

fun : pointer to user-function.
i : 0-based parameter index.
Returns : 1 if parameter i of function fun is optional, otherwise 0.

user_func_get_return_type ()

int                 user_func_get_return_type           (const ufunc *fun);

fun : pointer to user-function.
Returns : the return type of function fun.

user_function_name_by_index ()

const char *        user_function_name_by_index         (int i);

i : the position of a user-function in the array of loaded functions.
Returns : the name of the function, or NULL if i is out of bounds.

user_function_index_by_name ()

int                 user_function_index_by_name         (const char *name,
                                                         fnpkg *pkg);

name : function name.
pkg : reference function package.
Returns : the 0-based position of a function of name name belonging to package pkg, or -1 if there is no such function.

user_function_set_debug ()

int                 user_function_set_debug             (const char *name,
                                                         int debug);

Enables or disables debugging for a user-defined function.

name : the name of the function.
debug : boolean, if 1 then start debugging function, if 0 then stop debugging.
Returns : 0 on success, non-zero if no function is specified or if the function is not found.

function_names_init ()

void                function_names_init                 (void);


next_available_function_name ()

const char *        next_available_function_name        (int *idxp);

idxp :
Returns :

gretl_compiling_function ()

int                 gretl_compiling_function            (void);

Returns :

gretl_function_depth ()

int                 gretl_function_depth                (void);

Returns :

gretl_start_compiling_function ()

int                 gretl_start_compiling_function      (const char *line,
                                                         PRN *prn);

Responds to a command of the form "function ...". In most cases, embarks on compilation of a function, but this also handles the construction "function foo delete".

line : command line.
prn : printing struct for feedback.
Returns : 0 on success, non-zero on error.

gretl_function_append_line ()

int                 gretl_function_append_line          (const char *line);

Continuation of definition of user-function.

line : line of code to append.
Returns : 0 on success, non-zero on error.

gretl_is_public_user_function ()

int                 gretl_is_public_user_function       (const char *name);

name : name to test.
Returns : 1 if name is the name of a user-defined function that is not a private member of a function package, otherwise 0.

gretl_function_exec ()

int                 gretl_function_exec                 (ufunc *u,
                                                         fnargs *args,
                                                         int rtype,
                                                         double ***pZ,
                                                         DATAINFO *pdinfo,
                                                         void *ret,
                                                         char **descrip,
                                                         PRN *prn);

u :
args :
rtype :
pZ :
pdinfo :
ret :
descrip :
prn :
Returns :

gretl_func_get_arg_name ()

char *              gretl_func_get_arg_name             (const char *argvar,
                                                         int *err);

argvar :
err :
Returns :

object_is_const ()

int                 object_is_const                     (const char *name);

Checks whether the named object currently has 'const' status, by virtue of it's being made available as a const argument to a user function.

name : name of object (e.g. matrix).
Returns : non-zero if the object is const, 0 if it is not.

sample_range_get_extrema ()

void                sample_range_get_extrema            (const DATAINFO *pdinfo,
                                                         int *t1,
                                                         int *t2);

Fills out t1 and t2, making allowance for the possibility that we're currently executing a function, on entry to which the sample range was restricted: within the function, we are not allowed to overstep the bounds set on entry.

pdinfo : dataset info.
t1 : location to receive earliest possible starting observation.
t2 : location to receive latest possible ending observation.

get_funcerr_message ()

const char *        get_funcerr_message                 (void);

Returns :

function_return_type_from_string ()

int                 function_return_type_from_string    (const char *s);

s :
Returns :

gretl_function_print_code ()

int                 gretl_function_print_code           (ufunc *u,
                                                         PRN *prn);

Prints out function fun to prn, script-style.

u :
prn : printing struct.
Returns : 0 on success, non-zero if fun is NULL.

function_package_new ()

fnpkg *             function_package_new                (const char *fname,
                                                         char **pubnames,
                                                         int n_pub,
                                                         char **privnames,
                                                         int n_priv,
                                                         int *err);

Allocates a new package with filename-member fname, including the public and private functions named in pubnames and privnames. Note that this function does not cause the package to be written to file; for that, see write_function_package().

fname : filename for package.
pubnames : array of names of public functions.
n_pub : number of strings in pubnames.
privnames : array of names of private functions (or NULL).
n_priv : number of strings in privnames (may be 0).
err : location to receive error code.
Returns : pointer to package on success, NULL on error.

function_package_connect_funcs ()

int                 function_package_connect_funcs      (fnpkg *pkg,
                                                         char **pubnames,
                                                         int n_pub,
                                                         char **privnames,
                                                         int n_priv);

Looks up the functions named in pubnames and privnames and adds pointers to these functions to pkg, hence marking the functions as belonging to pkg.

pkg : function package.
pubnames : array of names of public functions.
n_pub : number of strings in pubnames.
privnames : array of names of private functions (or NULL).
n_priv : number of strings in privnames (may be 0).
Returns : 0 on success, non-zero on error.

function_package_set_properties ()

int                 function_package_set_properties     (fnpkg *pkg,
                                                         ...);

pkg :
... :
Returns :

function_package_get_properties ()

int                 function_package_get_properties     (fnpkg *pkg,
                                                         ...);

pkg :
... :
Returns :

function_package_get_name ()

const char *        function_package_get_name           (fnpkg *pkg);

pkg : function package.
Returns : the name of the package.

function_package_write_file ()

int                 function_package_write_file         (fnpkg *pkg);

Write out pkg as an XML file, using the filename recorded in the package.

pkg : function package.
Returns : 0 on success, non-zero on error.

check_function_needs ()

int                 check_function_needs                (const DATAINFO *pdinfo,
                                                         FuncDataReq dreq,
                                                         int minver);

Checks whether the requirements in dreq and minver are jointly satisfied by the current dataset and gretl version.

pdinfo : pointer to dataset info.
dreq : function data requirements flag.
minver : function minimum program version requirement.
Returns : 0 if all is OK, 1 otherwise.

write_session_functions_file ()

int                 write_session_functions_file        (const char *fname);

fname :
Returns :

read_session_functions_file ()

int                 read_session_functions_file         (const char *fname);

fname :
Returns :

get_function_package_by_filename ()

fnpkg *             get_function_package_by_filename    (const char *fname);

fname :
Returns :

load_function_package_from_file ()

int                 load_function_package_from_file     (const char *fname);

fname :
Returns :

function_package_unload_by_filename ()

void                function_package_unload_by_filename (const char *fname);

Unloads the specified function package from memory, if it is currently loaded. The functions 'owned' by the package are not destroyed; they become available for inclusion in other packages.

fname : package filename.

function_package_unload_full_by_filename ()

void                function_package_unload_full_by_filename
                                                        (const char *fname);

Unloads the specified function package from memory, if it is currently loaded. The functions 'owned' by the package are also unloaded from memory.

fname : package filename.

print_function_package_info ()

int                 print_function_package_info         (const char *fname,
                                                         PRN *prn);

fname :
prn :
Returns :

print_function_package_code ()

int                 print_function_package_code         (const char *fname,
                                                         PRN *prn);

fname :
prn :
Returns :

get_packaged_function_by_name ()

ufunc *             get_packaged_function_by_name       (const char *name,
                                                         fnpkg *pkg);

name :
pkg :
Returns :

get_function_file_header ()

int                 get_function_file_header            (const char *fname,
                                                         char **pdesc,
                                                         char **pver);

fname :
pdesc :
pver :
Returns :

update_function_from_script ()

int                 update_function_from_script         (const char *funname,
                                                         const char *path,
                                                         fnpkg *pkg);

funname :
path :
pkg :
Returns :

user_function_help ()

int                 user_function_help                  (const char *fnname,
                                                         PRN *prn);

Looks for a function named fnname and prints as much help information as possible.

fnname : name of function.
prn : printing struct.
Returns : 0 on success, non-zero if the function is not found.

gretl_functions_cleanup ()

void                gretl_functions_cleanup             (void);

For internal use: frees all resources associated with user-defined functions and function packages.


fn_args_new ()

fnargs *            fn_args_new                         (void);

Returns : a newly allocated, empty array of function arguments, or NULL of failure.

fn_args_free ()

void                fn_args_free                        (fnargs *args);

args :

push_fn_arg ()

int                 push_fn_arg                         (fnargs *args,
                                                         int type,
                                                         void *p);

Appends a new argument of the specified type and value to the array args.

args : existing array of function arguments.
type : type of argument to add.
p : pointer to value to add.
Returns : 0 on success, non-zero on failure.

adjust_indent ()

void                adjust_indent                       (const char *line,
                                                         int *this_indent,
                                                         int *next_indent);

line :
this_indent :
next_indent :