/*
The files demo_plugin.c and gnuplot_plugin.h serve as templates
showing how to create an external shared object containing functions
that can be accessed from inside a gnuplot session using the import
command. For example, after compiling this file into a shared
object (gnuplot_plugin.so or gnuplot_plugin.dll) the functions it
contains can be imported as shown:
gnuplot> import divisors(x) from "demo_plugin"
gnuplot> import mysinc(x) from "demo_plugin:sinc"
gnuplot> import nsinc(N,x) from "demo_plugin"
*/
#include "gnuplot_plugin.h"
#include
/* This function returns the number of divisors of the first argument */
DLLEXPORT struct value divisors(int nargs, struct value *arg, void *p)
{
int a = IVAL(arg[0]);
int i = 1;
int j = a;
struct value r;
r.type = INTGR;
r.v.int_val = 0;
/* Enforce a match between the number of parameters declared
* by the gnuplot import command and the number implemented here.
*/
RETURN_ERROR_IF_WRONG_NARGS(r, nargs, 1);
/* Sanity check on argument type */
RETURN_ERROR_IF_NONNUMERIC(r, arg[0]);
while (i