Note that there are some explanatory texts on larger screens.

plurals
  1. PONode.js addon class member functions
    primarykey
    data
    text
    <p>The code to expose a static member function of a C++ class in the javascript object looks something like this</p> <pre><code>tpl-&gt;InstanceTemplate()-&gt;Set( String::NewSymbol("thefunc"), FunctionTemplate::New(myclass::myfunc)-&gt;GetFunction() ); </code></pre> <p>Where <code>thefunc</code> is the name of the function accessible from javascript that maps to the static member <code>myfunc</code> of the class <code>myclass</code>.</p> <p>Since the method is static we have to access all class instance members via some instance pointer and write some boilerplate code to get at it. For example:</p> <pre><code>static Handle&lt;Value&gt; myclass::myfunc( const Arguments &amp;args ) { myclass *instance = Unwrap&lt;myclass&gt;( args.This() ); // now use 'instance' like 'this' return True(); } </code></pre> <p>I want to know if it's possible to set a member function in the interface and bind it to the class instance to avoid static functions with boilerplate and have the system call directly into my non-static method so I can use the 'this' pointer.</p> <p>I can think of a ugly way that involves <code>#define</code> expanding to a template class containing a proxy function that unwraps 'this' and forwards all calls to the member function, which would result in setup code similar to this:</p> <pre><code>DECLARE_MEMBER_FUNCTION( thefunc_handle, myclass, myfunc ); tpl-&gt;InstanceTemplate()-&gt;Set( String::NewSymbol("thefunc"), thefunc_handle ); </code></pre> <p>But it seems likely that Node.js already supports this or that someone has devised a better solution.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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. 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