Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Array of Objects

29 views
Skip to first unread message

Digambar Rasal

unread,
Dec 17, 2009, 10:34:39 AM12/17/09
to
Hi,

I am writing scriptable plugin and I am sure lot of people must have
faced similar problem.

I need to pass Array from Javascript and return Array of NPObjects to
Javascript from NPAPI plugin. But there is not documentation about how
this is achieved.

please reply if you think of something or have documentation links or
sample code.

cheers,
Digambar

Benjamin Smedberg

unread,
Dec 17, 2009, 10:54:59 AM12/17/09
to
On 12/17/09 10:34 AM, Digambar Rasal wrote:

> I need to pass Array from Javascript and return Array of NPObjects to
> Javascript from NPAPI plugin. But there is not documentation about how
> this is achieved.

An Array is just a JS object, so you can script it like any other NPObject.
For example:

To create a new Array object:

* get NPNVWindowNPObject
* call NPN_Evaluate(npp, windowobject, "new Array()", resultvariant);

To fill it with objects:

NPVariant[3] arrayitems;
for (int i = 0; i < 3; ++i) {
NPIdentifier id = NPN_GetIntIdentifier(i);
NPN_SetProperty(npp, arrayobject, id, &arrayitems[i]);
};

etc...

--BDS

Digambar Rasal

unread,
Dec 18, 2009, 5:25:24 AM12/18/09
to
Looks good now. I have figured out how to return Array of objects
defined in plugin which can't be created from Javascript.

Say Object - Note which has date and string as properties. From
JAVAScript, there is call to get complete list of notes. So Plugin
need to create object big enough to hold all notes with
NPN_createObject ( ) i.e. in allocate sizeofNOTE X number of notes is
allocated and returned. When there is access to Note[n],
NPN_GetProperty returns pointer to specific Object.

- Digambar

taxilian

unread,
Dec 19, 2009, 5:10:48 AM12/19/09
to

this actually is not too hard. I want to first add something to the
previous post; while NPN_Evaluate does get the job done, it would
really be better to just call NPN_Invoke(npp, windowobject,
NPN_GetStringIdentifier("Array"), ...)

The reason is that firefox seems to handle things differently when you
evaluate them; it's as if you injected that javascript into the page.
you can actually see it with Firebug; thus, eventually, it could take
up resources if you make calls like that a lot. Also, it seems to be
much slower. Avoid using Evaluate whenever you can -- which has
always been good javascript etiquite.

So, once you have created your Array (because the result will be an
NPObject with that object, just call NPN_Invoke on the array NPObject
with push (easier to deal with than a for loop and indexes) for each
NPObject that you have created that you want to be accessible to the
page. Remember to call NPN_RetainObject whenever you store an
NPObject in a NPVariant to go to the page.

Good luck, hope that helps.

imsh...@gmail.com

unread,
Jul 9, 2013, 7:38:30 AM7/9/13
to
Can you explain in some detail...?
0 new messages