[Gambas-devel] Returning a reference to an array ...
Gareth Bult
gareth at ...560...
Mon Jan 12 19:03:47 CET 2009
Ok,
I'm obviously being a bit dull .. however, the following code now seems to
compile OK, however then I try to run it, Gambas reports "No return value".
[so GB.ReturnObject(array) isn't working??]
BEGIN_METHOD_VOID(CCONNECTION_audio_devices)
struct iaxc_audio_device *devs;
int ndevs,input,output,ring,i;
GB_ARRAY array;
CIAX2DEVICE *dev;
iaxc_audio_devices_get(&devs,&ndevs,&input,&output,&ring);
GB.Array.New(&array, (GB_TYPE)GB.FindClass("IAX2Device"), 1);
for (i = 0; i < ndevs; i++)
{
GB.New((void**)&dev,GB.FindClass("IAX2Device"),NULL,NULL);
GB.Ref(dev);
GB.NewString(&dev->name,devs[i].name,0);
*((void **)GB.Array.Get(array, i)) = dev;
}
GB.ReturnObject(array);
return;
END_METHOD
Does the above seem "sane"?
Am I missing something critical??
I think I've had this code before and had the same problem, been trying lots of different approaches ...
Gareth.
----- Original Message -----
From: "Benoit Minisini" <gambas at ...1...>
To: "mailing list for gambas developers" <gambas-devel at lists.sourceforge.net>
Sent: Monday, 12 January, 2009 4:14:16 PM GMT +00:00 GMT Britain, Ireland, Portugal
Subject: Re: [Gambas-devel] Returning a reference to an array ...
On lundi 12 janvier 2009, Gareth Bult wrote:
> Hi,
>
> I inserted your code to start with just replacing <<number of devices>> ...
> I get;
>
> iax2.c:455: warning: passing argument 2 of 'GB.Array.New' makes integer
> from pointer without a cast iax2.c:459: warning: dereferencing 'void *'
> pointer
> iax2.c:459: error: invalid use of void expression
> iax2.c:460: error: void value not ignored as it ought to be
>
> When compiling ..
>
> GB.Array.New seems to be expecting a GB_T constant , whereas GB.FindClass
> is returning a pointer (???)
>
> So whereas I would love to use;
>
> #GB.Array.New(&array, GB.FindClass("IAX2Device"), <<number of devices>>);
>
> It seems this option is not available .. which is why I was using;
>
> #GB.Array.New(&array,GB_T_OBJECT,ndevs);
>
> Help!
>
> Gareth.
>
I forgot a cast.
GB.Array.New(&array, (GB_TYPE)GB.FindClass("IAX2Device"), <<number of
devices>>);
You can use GB_T_OBJECT. But now you can have specialized arrays in Gambas, so
why not using them? :-)
--
Benoit Minisini
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Gambas-devel mailing list
Gambas-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-devel
--
Managing Director, Encryptec Limited
Tel: 0845 5082719, Mob: 0785 3305393
Email: gareth at ...560...
Statements made are at all times subject to Encryptec's Terms and Conditions of Business, which are available upon request.
More information about the Devel
mailing list