LWJGL Forum

Programming => LWJGL Documentation => Topic started by: kenzierocks on December 30, 2014, 17:20:33

Title: Incorrect documentation for callbacks
Post by: kenzierocks on December 30, 2014, 17:20:33
Callbacks are listed as functional interfaces in the Binding section, when they are actually abstract classes. An abstract class with one abstract method is not a functional interface.

From 1.5 Bindings FAQ (https://github.com/LWJGL/lwjgl3-wiki/wiki/1.5.-Bindings-FAQ#how-can-callbacks-from-native-code-be-configured):
Quote
they are functional interfaces by definition, so SAM conversions in Java 8 can naturally be applied on them.
Title: Re: Incorrect documentation for callbacks
Post by: kenzierocks on December 30, 2014, 17:24:32
Oh, I have discovered the SAM interface of each callback. This might need to be made clearer in the documentation.
Title: Re: Incorrect documentation for callbacks
Post by: kenzierocks on December 30, 2014, 17:29:07
Additionally, the SAM interfaces do not work. You cannot pass them to the callback areas.
Title: Re: Incorrect documentation for callbacks
Post by: SHC on December 30, 2014, 17:42:52
They are working, I use them all the time. Here is a small example.

Code: [Select]
private void myKeyCallback(long window, int key, int scancode, int action, int mods)
{
    // Do something with the input here
}

GLFWKeyCallback keyCallback = GLFWKeyCallback(this::myKeyCallback);
glfwSetKeyCallback(keyCallback);
This is how you should use it. If you are still in confusion, I had written a tutorial here (http://goharsha.com/lwjgl-tutorial-series/window-callbacks/)
Title: Re: Incorrect documentation for callbacks
Post by: spasi on December 30, 2014, 17:55:12
Hey kenzierocks,

The Bindings FAQ has not been updated with the latest changes. Specifically, the information on callbacks and structs is out of date.

Callbacks are indeed abstract classes now, but as SHC explained, there's a relatively clean workaround for using lambdas and method references. This was originally explained in this post (http://forum.lwjgl.org/index.php?topic=4800.msg29540#msg29540).