Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I guess I'm answering my own question...</p> <p>The solution I found (and I would still appreciate comments on its validity, especially if you think there's a better way of doing it) was to allocate an NPObject derived structure which has a pointer to my implementation class in the allocate() function I expose to Firefox from my plugin. I then store a pointer to that NPObject in the NPP's pdata member, in NPP_New(). </p> <p>In invoke(), I cast the NPObject pointer I get to the derived structure's additional members, so that I can get a pointer to the instance of the implementation class. </p> <p>That, as far as I can tell, is the intent of the design - NPObject objects are instances of the NPClass they point to, they implement methods and properties through the NPClass function pointers that deal with these entities, and any private data is expected to be allocated and deallocated by the implementation, and its format is unspecified.</p> <p>It would look something like this:</p> <pre><code> static NPClass refObject = { NP_CLASS_STRUCT_VERSION, My_Allocate, My_Deallocate, NULL, My_HasMethod, My_Invoke, My_InvokeDefault, My_HasProperty, My_GetProperty, NULL, NULL, }; class MyImplClass { // Implementation goes here }; struct MyNPObject : public NPObject { MyImplClass *my_impl_instance; }; // This is just a bit of memory management - Mozilla wants us to allocate our own memory: NPObject *My_Allocate(NPP inst, NPClass *) { // We initialize the structure in NPP_New() below return (NPObject *)malloc(sizeof(MyNPObject)); } NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved ) { NPObject *scriptable_object = npnfuncs-&gt;createobject(instance, &amp;refObject); npnfuncs-&gt;retainobject(scriptable_object); MyImplClass *new_player = new MyImplClass(); instance-&gt;pdata = scriptable_object; ((MyNPObject*)instance-&gt;pdata)-&gt;my_impl_instance = new_player; return NPERR_NO_ERROR; </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload