Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Stateful lambdas cannot be turned into function pointers.</p> <p>Only lambdas with no state can be turned into function pointers.</p> <p>Your state needs to slide in through some back door. <code>glutDisplayFunc</code>, only takes a stateless function pointer. Modifying it isn't possible.</p> <p>If you can find a back door to store something, you can use that to store an arbitrary lambda. In this case, <code>glutDisplayFunc</code> is associated with the current window. Is there any place you can shove state in the current window, and figure out which one that is?</p> <p>Suppose you find such a <code>void*</code>. Then simply allocate a <code>std::function&lt;void()&gt;</code>, shove it in there, and register the following lambda:</p> <pre><code>void AClass::b(void (*func)()) { auto funcA = [func] () { [that first low level operation]; func(); //Which is: void a(void); [the second low level operation]; }; registerPVoidSomewhere( new std::function&lt;void()&gt;( funcA ) ); register([]() { void* pVoid = getPVoidFromWhereIHideItAbove(); std::function&lt;void()&gt;* pFunc = reinterpret_cast&lt;std::function&lt;void()&gt;*&gt;( pVoid ); if (pFunc) { (*pFunc)(); }; } ); } </code></pre> <p>Now, I'm betting that when the <code>glutDisplayFunc</code> is called, it is called from a context when you can ask <code>glut</code> what the current window is. Maybe that window has a place for a user-defined <code>void*</code>, or you could have a global map from window pointer to <code>void*</code> that you manage (in that second case, you could even have a global map from window pointer to <code>std::function&lt;void()&gt;</code>, and get rid of that nasty casting).</p>
    singulars
    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.
    1. 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