On Feb 22, 2:17 pm, "Igor Tandetnik" <[EMAIL PROTECTED]> wrote:
> tradiate <[EMAIL PROTECTED]> wrote:
> > I have a C++ XPCOM object that I have exposed to JavaScript. Calls
> > from the JS environment to methods on my C++ object are working fine.
> > I'm now introducing a new method to my C++ object that needs to return
> > a JS Array back to the JavaScript caller. Is there an example in the
> > mozilla tree that demonstrates how to do this sort of thing? If not,
> > does anyone care to share snippet(s), or point me to a site, that
> > illustrates the technique?
>
> // XPIDL
> void getArray(out unsigned long count, [array, size_is(count), retval]
> out long retv);
>
> // C++
> NS_IMETHODIMP MyComponent::GetArray(PRUint32* count, PRInt32** retv) {
> *count = 10;
> *retv = (PRInt32*)nsMemory::Alloc(*count * sizeof(PRInt32));
>
> for (int i = 0; i < 10; ++i) (*retv)[i] = i;
>
> return NS_OK;
>
> }
>
> // JavaScript
> var arr = myComponent.getArray({});
>
> Igor Tandetnik
Thanks, Igor. This is very close to what I need. Is there a way to
set things up so that the JS code doesn't have to be coded as
xxx.getArray({})? I'd like to lose the {} in the parm list, but as
this stands, if I omit the {} in the parm list, I get an XPC exception
about not enough parms being specified. I want my JS API to be
uncluttered.
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom