[Prev][Next][Index][Thread]

# Re: register_function line

- Date: Wed, 29 May 1996 19:32:52 PDT
- From:
- Reply-To:
- Content-Transfer-Encoding: quoted-printable
- Content-Type: text/plain; charset=ISO-8859-1
- Newsgroups: local.moo
- Organization: Where Stormnet meets the Internet
- References: <Pine.A32.3.91.960528211559.22613A-100000@erc.jscc.cc.tn.us> <Pine.LNX.3.91.960529192149.494A-100000@ralin.mistral.co.uk>

    Followup to:  <Pine.LNX.3.91.960529192149.494A-100000@ralin.mistral.co.uk>
    By author:    bartmoss@mistral.co.uk
    In newsgroup: local.moo
    >
    > > float bf_distance(float stop[3], float start[3])
    >
    > The register line looked fine, did you notice that
    > arglist.v.list[i].v.fnum was a pointer?
    >

    More importantly, the calling convention for a builtin function is:

    static package
    bf_functionname(Var arglist, Byte next, void *vdata, Objid progr)
    {
    	...
    }

    In your case you have not only to unroll the arglist (which is a
    variable which is always a list) but also check the constitution of
    the component lists (since that is not done automatically).

    Completely untested top-of-my-head code:

    static package
    bf_distance(Var arglist, Byte next, void *vdata, Objid progr)
    {
      double stop[3], start[3], *dp, dist;
      Var r;
      int i, j;

      for ( i = 1 ; i <= 2 ; i++ )
        {
          dp = (i==1) ? stop : start;

          r = arglist.v.list[i];
          if (r.v.list[0].num != 3)
    	{
    	  free_var(arglist);
    	  return make_error_pack(E_INVARG);
    	}

          for ( j = 1 ; i <= 3 ; i++ )
    	{
    	  if ( r.v.list[j].type != TYPE_FLOAT )
    	    {
    	      free_var(arglist);
    	      return make_error_pack(E_INVARG);
    	    }
    	  dp[j-1] = *r.v.list[j].v.fnum;
    	}
        }

      /* Do your thing, for example... */

      dist = 0.0;
      for ( i = 0 ; i < 3 ; i++ )
        dist += (start[i]-stop[i])*(start[i]-stop[i]);
      dist = sqrt(dist);

      return make_var_pack(new_float(dist));
    }

    --
    PGP public key available - finger hpa@zytor.com
    "The earth is but one country, and mankind its citizens."  --  Bahá'u'lláh
    Just Say No to Morden * Save Babylon 5: http://www.babylon5.com/cmp/support/

Follow-Ups:

- Re: register_function line

- From: Diana L Harris <dlh5226@erc.jscc.cc.tn.us>

References:

- register_function line

- From: Diana L Harris <dlh5226@erc.jscc.cc.tn.us>

- Re: register_function line

- From: bartmoss@mistral.co.uk

- Prev: Re: register_function line
- Next: Re: register_function line
- Index: MOO-cows
- Thread: MOO-cows

Home | Subject Index | Thread Index