[DGD] (mis)adventures with extensions

Felix A. Croes felix at dworkin.nl
Wed Sep 26 16:22:02 CEST 2007


"chris ." <psych_mayo at hotmail.com> wrote:

> 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.

That is because you use the second argument (arg1, or text) instead of
the first argument (arg0, or path) to open the file.

Note that you also make a copy of the argument strings, presumably
because the example lower_case function does so.  Since you are not
passing these copied strings back to the LPC layer, this is pointless,
and it also introduces a memory leak.

Finally, this does not do what you think it does:

>   fwrite(arg1,sizeof(arg1[0]), sizeof(arg1),buffy);

It should be something like:

    fwrite(DGD_STRING_TEXT(text), sizeof(char), DGD_STRING_LENGTH(text),
	   buffy);

Regards,
Dworkin



More information about the DGD mailing list