From 0cfe4e6352f19c554779451dc24acb21796f0250 Mon Sep 17 00:00:00 2001 From: anon Date: Tue, 10 Dec 2024 20:38:37 +0100 Subject: [PATCH] +TK from C --- C_C++/Tcl/button_help.c | 41 +++++++++++++++++++++++++++++++++++++++ C_C++/Tcl/button_help.tcl | 7 +++++++ 2 files changed, 48 insertions(+) create mode 100644 C_C++/Tcl/button_help.c create mode 100644 C_C++/Tcl/button_help.tcl diff --git a/C_C++/Tcl/button_help.c b/C_C++/Tcl/button_help.c new file mode 100644 index 0000000..c39d10a --- /dev/null +++ b/C_C++/Tcl/button_help.c @@ -0,0 +1,41 @@ +// @BAKE gcc $@ -o $*.out $(pkg-config --cflags --libs tcl tk) +#include +#include +#include +#include +#include + +// our button callback +static +int Tcl_baah(ClientData clientData, Tcl_Interp * interp, int argc, const char * * argv) { + puts("BAAAAAAAH"); + return TCL_OK; +} + +static +void tcl_run(void) { + Tcl_Interp * interp = Tcl_CreateInterp(); + Tcl_Init(interp); + Tk_Init(interp); + + Tcl_CreateCommand(interp, "baah", Tcl_baah, (ClientData)NULL, (void (*)())NULL); + + /* if only it were past 2023 we could have #embed! + * oh wait... + */ + int result = Tcl_EvalFile(interp, "button_help.tcl"); + if (result == TCL_ERROR) { + fprintf(stderr, "Tcl script execution failed: %s\n", Tcl_GetStringResult(interp)); + exit(1); + } + + Tk_MainLoop(); +} + +signed main() { + pthread_t tcl_thread; + pthread_create(&tcl_thread, NULL, (void *(*)(void*))tcl_run, (void*)NULL); + + // whatever you want + while (1) { ; } +} diff --git a/C_C++/Tcl/button_help.tcl b/C_C++/Tcl/button_help.tcl new file mode 100644 index 0000000..6fa2e5c --- /dev/null +++ b/C_C++/Tcl/button_help.tcl @@ -0,0 +1,7 @@ +package require Tk + +wm title . "Button example" +frame .main +pack .main +button .mybutton -text "press me" -command baah +pack .mybutton