Re: Ideas for parsing parameters in a STk Extension

From: Erick Gallesio <eg_at_kaolin.unice.fr>
Date: Mon, 27 Feb 1995 17:39:11 +0000

>
> I am on my way to add some extensions to STk. But now I need to add
> new primitives which will accept keywords as parameters. My primitive
> should be able to parse those keyvalues in order to take
> decisions..but I didn't succeded to implement so.
>
> Does anybody can give me a hint on how to do that? I am a bit
> confused..
>

For implementing a primitive with a list of parameters you have to use a
tc_lsubr. This kind of function has two parameters: the list of parameters
(a SCM object) and the length of this list (a C int). Following example
returns a point (represented as a cons). Values are given with the :x and :y
keywords
and have a 0 default value.

This primitive can be implemeneted with the following C function

        PRIMITIVE make_point(SCM l, int unused_length)
        {
          static char keyx[] = ":x";
          static char keyy[] = ":y";
          SCM x, y;
          
          x = STk_get_keyword(STk_makekey(keyx), l, STk_makeinteger(0));
          if (NINTEGERP(x)) Err("make-point: bad value for x", x);
        
          y = STk_get_keyword(STk_makekey(keyy), l, STk_makeinteger(0));
          if (NINTEGERP(y)) Err("make-point: bad value for y", y);
        
          return Cons(x, y);
        }

Hope it suffices to make your extension.


                -- Erick
Received on Mon Feb 27 1995 - 17:47:49 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST