cppfront fltk program of a button with callback function

Why cppfront. Just because you can. Disclaimer for bigger projects problems might arise, use at own risk.

Put github cppfront code in ../cppfront directory

cpp2 program hello.cpp2 :
Code:
// import fltk; // Assuming fltk modules or standard headers
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>

String: type == std::string; 
auto&   Cout =  std::cout;
#define Endl  std::endl
#define Format  std::format


my_callback: (w: *Fl_Widget, data: *void) = {
    Cout << "Button clicked!" << Endl;
}

main: () -> int = {
    window := Fl_Window(300, 180, "Cppfront FLTK");
    btn := Fl_Button(100, 70, 100, 40, "Click Me");
    btn.callback(my_callback);
    window.end();
    window.show();
    return Fl::run();
}

Script to compile,link,run :
Code:
rm hello.exe
rm hello.cpp
export MYCPP2="./hello.cpp2"
export  MYCPP="./hello.cpp"
export  MYEXE="./hello.exe"
export CPPFRONT_INCLUDE="../cppfront/source"
export CPPCOMPILER="clang++21"
export CPPSTANDARD="c++20"
export CPPFRONTFLAGS="-import-std -include-std -emit-cppfront-info -line-paths -format-colon-errors"
./cppfront $MYCPP2 $CPPFRONTFLAGS -o $MYCPP
$CPPCOMPILER $MYCPP -I$CPPFRONT_INCLUDE -std=$CPPSTANDARD -o $MYEXE $(fltk-config --cxxflags --ldflags)
$MYEXE
 
Back
Top