hello ring team,
i support a c++ lib and in this lib come so many function that have such a function prototype:
void arrayFunk( char *arr[ ] )
Code generator does not support this prototype.
i tried to support it like this in ring.
my question is if there are other better ways that can work better.
i am also trying to clear the memory i have reserved.
// c funktion
void arrayFunk(const char *const arr[])
{
int i = 0;
while (arr[i] != NULL)
{
printf("... %s\n", arr[i]);
i++;
}
}
//+++++++++++++++++ my CF file
<register>
void arrayFunk(char *arr[ ] )
</register>
<code>
RING_FUNC(ring_arrayFunk)
{
if (RING_API_PARACOUNT != 1)
{
RING_API_ERROR(RING_API_BADPARACOUNT);
return;
}
if (!RING_API_ISLIST(1))
{
RING_API_ERROR(RING_API_BADPARATYPE);
return;
}
List *pList = RING_API_GETLIST(1);
int x;
int list_size = ring_list_getsize(pList);
char **str;
str = malloc(list_size * sizeof(char *));
for (x = 1; x <= ring_list_getsize(pList); x++)
{
if (ring_list_isstring(pList, x))
{
// printf("%s\n", ring_list_getstring(pList, x));
str[x - 1] = ring_list_getstring(pList, x);
//printf("%s\n", ring_list_getstring(pList, x));
}
}
str[x] = NULL;
arrayFunk(str);
/*
printf("____ %p\n", str);
for (int i = 0; i < list_size; i++)
{
printf("%p\n", str[i]);
free(str[i]);
}
*/
}
</code>
//++++++++++++++++++++++++ test.ring
loadlib("build/Debug/test.dll")
ls =["hi","hallo","welt","marc","sluca"]
arrayFunk(ls)
my question is if there are other better ways that can work better.
i am also trying to clear the memory i have reserved. after calling c funktion but
char **str;
str = malloc(list_size * sizeof(char *));
arrayFunk(str); // the code after hier dont work. how can i free memory
/*
printf("____ %p\n", str);
for (int i = 0; i < list_size; i++)
{
printf("%p\n", str[i]);
free(str[i]);
}
*/