Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct the Callback documentation #3

Merged
merged 1 commit into from
Jun 21, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions www/CallbacksAndClosures.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ Callbacks and Closures
======================

Callback declarations consist of a simple interface that extends the Callback interface and implements a callback method (or defines a single method of arbitrary name). Callbacks are implemented by wrapping a Java object method in a little bit of C glue code. The simplest usage resembles using anonymous inner classes to register event listeners. Following is an example of callback usage:

// Original C declarations
typedef void (*sig_t)(int);
sig_t signal(sig_t);
typedef void (*sig_t) (int);
sig_t signal(int sig, sig_t func);
int SIGUSR1 = 30;

// Equivalent JNA mappings
public interface CLibrary extends Library {
int SIGUSR1 = 30;
interface sig_t extends Callback {
void invoke(int signal);
void invoke(int signal);
}
sig_t signal(int sig, sig_t fn);
int raise(int sig);
Expand All @@ -32,7 +33,7 @@ Callback declarations consist of a simple interface that extends the Callback in
...

Here is a more involved example, using the Win32 APIs to enumerate all native windows:

// Original C declarations
typedef int (__stdcall *WNDENUMPROC)(void*,void*);
int __stdcall EnumWindows(WNDENUMPROC,void*);
Expand Down