| Libgretl Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | ||||
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);
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;
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. |
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.
|
int fn_n_params (const ufunc *fun);
fun : |
pointer to user-function. |
| Returns : | the number of parameters associated with fun.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
int user_func_get_return_type (const ufunc *fun);
fun : |
pointer to user-function. |
| Returns : | the return type of function fun.
|
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.
|
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.
|
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. |
const char * next_available_function_name (int *idxp);
idxp : |
|
| Returns : |
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. |
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. |
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.
|
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 : |
char * gretl_func_get_arg_name (const char *argvar,
int *err);
argvar : |
|
err : |
|
| Returns : |
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. |
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. |
int function_return_type_from_string (const char *s);
s : |
|
| Returns : |
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.
|
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.
|
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. |
int function_package_set_properties (fnpkg *pkg, ...);
pkg : |
|
... : |
|
| Returns : |
int function_package_get_properties (fnpkg *pkg, ...);
pkg : |
|
... : |
|
| Returns : |
const char * function_package_get_name (fnpkg *pkg);
pkg : |
function package. |
| Returns : | the name of the package. |
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. |
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. |
int write_session_functions_file (const char *fname);
fname : |
|
| Returns : |
int read_session_functions_file (const char *fname);
fname : |
|
| Returns : |
fnpkg * get_function_package_by_filename (const char *fname);
fname : |
|
| Returns : |
int load_function_package_from_file (const char *fname);
fname : |
|
| Returns : |
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. |
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. |
int print_function_package_info (const char *fname,
PRN *prn);
fname : |
|
prn : |
|
| Returns : |
int print_function_package_code (const char *fname,
PRN *prn);
fname : |
|
prn : |
|
| Returns : |
ufunc * get_packaged_function_by_name (const char *name, fnpkg *pkg);
name : |
|
pkg : |
|
| Returns : |
int get_function_file_header (const char *fname,
char **pdesc,
char **pver);
fname : |
|
pdesc : |
|
pver : |
|
| Returns : |
int update_function_from_script (const char *funname,
const char *path,
fnpkg *pkg);
funname : |
|
path : |
|
pkg : |
|
| Returns : |
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. |
void gretl_functions_cleanup (void);
For internal use: frees all resources associated with user-defined functions and function packages.
fnargs * fn_args_new (void);
| Returns : | a newly allocated, empty array of function
arguments, or NULL of failure.
|
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. |