[DGD] (mis)adventures with extensions

chris . psych_mayo at hotmail.com
Wed Sep 26 16:41:03 CEST 2007








> From: psych_mayo at hotmail.com
> To: dgd at dworkin.nl
> Date: Wed, 26 Sep 2007 09:52:35 +0000
> Subject: [DGD] (mis)adventures with extensions
> 
> 
> I have never written in c before (lpc all my life), but after a crash course educational binge i managed to concoct what i think may be sound c code.  I think the problem is my understanding of the extension interface.
> 
> I made a function write_bin(string filepath, string text).  It writes a binary file from text to the file in filepath.
> When i send input with a path, (from my / root in this case), it writes a binary file, but not where i tell it to, but in /dgd/mud/.  It doesnt use the filename i gave it, but uses the second argument input for a filename.  The code for the extension is as follows:
> 
> # include 
> # include "dgd_ext.h"
> 
> /* write_bin(string path, string text) */
> static void write_bin(DGD_FRAME_T f, int nargs, DGD_VALUE_T *retval) {
>   DGD_VALUE_T val;
>   DGD_STRING_T path;
>   DGD_STRING_T text;
>   char *arg0;
>   char *arg1;
>   unsigned int i;
>   FILE *buffy;
>   /* fetch the arguments */
>   val = DGD_FRAME_ARG(f, nargs, 0);
>   path = DGD_STRING_GETVAL(val);
>   val = DGD_FRAME_ARG(f, nargs, 1);
>   text = DGD_STRING_GETVAL(val);
>   /* make copies */
>   path = DGD_STRING_NEW(DGD_STRING_TEXT(path), DGD_STRING_LENGTH(path));
>   arg0 = DGD_STRING_TEXT(path);
>   text = DGD_STRING_NEW(DGD_STRING_TEXT(text), DGD_STRING_LENGTH(text));
>   arg1 = DGD_STRING_TEXT(text);
>   buffy = fopen(arg1,"ab");
>   fwrite(arg1,sizeof(arg1[0]), sizeof(arg1),buffy);
>   fclose(buffy);
>   }
> 
> static char write_bin_proto[] = { DGD_TYPE_VOID, DGD_TYPE_STRING, DGD_TYPE_STRING, 0 };
> static DGD_EXTKFUN_T kf[1] = {
>     "write_bin",
>     write_bin_proto,
>     &write_bin
> };
> 
> void extension_init(void)
> {
>     DGD_EXT_KFUN(kf, 1);
> }
> 
> Thank you for your time,
> -chris
> _________________________________________________________________
> Connect to the next generation of MSN Messenger 
> http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline
> ___________________________________________
> https://mail.dworkin.nl/mailman/listinfo/dgd

_________________________________________________________________
News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx


More information about the DGD mailing list