[DGD]new arrays in extension kfuncs
Erwin Harte
harte at xs4all.nl
Sat Jan 20 05:51:24 CET 2001
On Sat, Jan 20, 2001 at 12:57:35AM +0000, boris wrote:
> Hello !
>
> I'm trying to create an 'string*' (array of strings) in an extension kfunc,
> but I got lost in all macros in 'dgd_ext.h'. Well, basicly I have a bunch of
> 'char*' and whant to create an LPC array of them. What is the correct way of
> creatig new LPC array ?
void
your_function(DGD_FRAME_T f, int nargs, DGD_VALUE_T *retval)
{
/*
* Assuming you have the 'char *' available in a nice array, and
* the total elements is known. You know best where you got 'em
* from anyway so that's a bit vague to me right now:
*/
int total;
char **lines;
/*
* This is where we build the array in, to be returned.
*/
DGD_ARRAY_T arr;
/*
* Because we're dealing with an array, it's useful to keep the
* current dataspace handy.
*/
DGD_DATA_T dataspace;
/*
* Loop variable.
*/
int i;
/*
* Now, without having tested this, I would try something like
* this:
*/
dataspace = DGD_FRAME_DATASPACE(f);
arr = DGD_ARRAY_NEW(dataspace, total);
for (i = 0; i < total; i++) {
/*
* Here's the DGD string we're going to create.
*/
DGD_STRING_T str;
/*
* This is assuming you have 0-terminated strings.
*/
str = DGD_STRING_NEW(lines[i], strlen(lines[i]));
DGD_ARRAY_ASSIGN(dataspace, arr, i, str);
}
DGD_RETVAL_ARRAY(retval, arr);
}
As said, it's untested, but it might help. :-)
Erwin.
--
Erwin Harte : `Don't mind Erwin, he gets crabby. :)'
harte at xs4all.nl : -- Par Winzell <zell at skotos.net>
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list