#include "gliim.h"
void get_factorial(gg_num f, gg_num *res)
{
*res = 1;
gg_num i;
for (i = 2; i <= f; i++) {
*res *= i;
}
}
#define MEMSIZE 200
void fact_msg (gg_num i, char **res)
{
char *r = gg_malloc (MEMSIZE);
gg_num f;
get_factorial (i, &f);
gg_num bw = snprintf(r, MEMSIZE, "Factorial value (message from C function) is %ld", f) + 1;
*res = gg_realloc (gg_mem_get_id(r), bw);
}
Copied!
extended-mode
begin-handler /example public
set-number fact
call-extended get_factorial (10, &fact)
@Factorial is <<p-num fact>>
set-string res
call-extended fact_msg (10, &res)
p-out res
@
end-handler
Copied!