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

NPObject to NPObject initilization

1 view
Skip to first unread message

Digambar Rasal

unread,
Dec 10, 2009, 1:29:40 PM12/10/09
to
In a plugin say video, after initilization of base object, further
objects are created by NPN->CreateObject.

As CreateObject just takes Class variable as arguement, is it
possible to send some initilisation data so that on allocate it can be
used in next class.

Here is snippet -

in main plugin instace -
NPP_New
{
ObjectA = NPN_CreateObject(npp, getClassA)
}

in Object/Class A on invoke API_abc

API_abc(args)
{
ObjectB = NPN_CreateObject(npp, getClassB);
}

So If I have to initlise data at Object B from Object A at creation
what is best way ?

Regards


taxilian

unread,
Dec 10, 2009, 3:12:39 PM12/10/09
to

I'm not sure if anyone can say that there is a "Best way", but I can
tell you how I normally do it. I just have a static method on my
NPObject class called "NewObject"; I pass in my browser object (which
has the pointers to NPN_CreateObject and the NPP handle) as well as
any initialization parameters that I may need and it returns the
created and initialized object. This also makes it easy to keep track
of the NPClass, since it can just be a static protected member
variable of that class.

You can see an example here:
http://code.google.com/p/firebreath/source/browse/src/NpapiPlugin/NPJavascriptObject.h
http://code.google.com/p/firebreath/source/browse/src/NpapiPlugin/NPJavascriptObject.cpp

Good luck,

Richard

Digambar Rasal

unread,
Dec 11, 2009, 4:20:51 AM12/11/09
to
I think I need to use NPN_Invoke on new object to call default which
initialises method with parameters. But thanks for reply. I find its
very easy to do with JS Objects which my platform doesn't support.

Cheers

taxilian

unread,
Dec 12, 2009, 1:06:03 PM12/12/09
to

Yes; the method I mentioned only works with objects that you
create. :-) NPN_Invoke and NPN_SetProperty will work on any
NPObject. I tend to be obsessively object oriented, but I'd probably
still create an object or method somewhere that takes the NPObject
params, creates the object, calls the appropriate initialization
(Invoke, SetProperty, whatever), and then returns it. For me, it's
nice to have it in one place. Since I can't have a real constructor,
using a construbor-type function to create the object seems like the
next best thing.

For what it's worth =]

Richard

0 new messages