FLTK logo

[fltk/fltk] Add lambdas with captures as callback option. (PR #1597)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
[  All Forums  |  Back to fltk.issues  ]
 
[ Previous Message ] [ New Message | Reply ] [ Next Message ]

[fltk/fltk] Add lambdas with captures as callback option. (PR #1597) Matthias Melcher 19:16 Sep 01  
 

As discussed in #1442, this is another proposal for adding std::function as a callback option. It's type safe, convenient, and removes UB function pointer casting. Capturing lambdas are available since C++11.

This implementation uses a template class to create an interface that can be used with any class that needs a callback interface, and is not derived from Fl_Widget (Fl_File_Chooser, for example).

In phase 1, I implemented the basic idea without changing the API at all. Feedback is highly appreciated. Commit 1 is tested on macOS with all apps in test and Fluid and compiles without any new warnings.

In phase 2, I will test Fl_Callback_Interface with Fl_File_Chooser.

In phase 3, I add std::function as a new callback option without changing the logic of the old callback system

Phase 4 is optional because it may break the API, but fixes ambiguities and undefined behavior in our current code. For example, casting void()(Fl_Widget*, long) to void()(Fl_Widget*, void*) is UB


You can view, comment on, or merge this pull request online at:

  https://github.com/fltk/fltk/pull/1597

Commit Summary

  • 66a7242 Extract Fl_Widget::callback into an Interface

File Changes

(3 files)

Patch Links:

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <fltk/fltk/pull/1597@github.com>

[ Direct Link to Message ]
 
     
[ Previous Message ] [ New Message | Reply ] [ Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.