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 


_______________________________________________
dev-tech-xpcom mailing list
dev-tech-xpcom@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to