The puzzle was to create a c source file named smwind.c demonstrating a trivial gtk-2.0 app. And it should compile and work under gcc.
And it was also required to convert via c2nim to a source named smwind.nim which will also compile and work under nim. No tweaking of the smwind.nim allowed.
The question is how to do this more cleanly than shown below. Here is smwind.c
#include "mingtk.h"
void mainProc()
{
GtkWidget *window;
// gtk_init (&argc, &argv);
#ifdef C2NIM
#@
gtk_init(nil,nil);
@#
#else
gtk_init(0,0);
#endif
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);
gtk_main();
}
#ifdef C2NIM
#@
mainProc()
@#
#else
int main(int argc,char **argv) { mainProc(); }
#endif
The mingtk.h is a minimalized version of gtk.h and is shown here for completeness. It is not expected to be changed. It is also converted to mingtk.nim via c2nim without tweaking.
/* minimum gtk.h */
#ifdef C2NIM
#cdecl
#define libgtk "libgtk-x11-2.0.so"
#dynlib libgtk
#endif
typedef struct { } GtkWidget;
/* Window types */
typedef enum
{
GTK_WINDOW_TOPLEVEL,
GTK_WINDOW_POPUP
} GtkWindowType;
void gtk_init(int *argc,char ***argv);
GtkWidget* gtk_window_new(GtkWindowType type);
void gtk_widget_show(GtkWidget *widget);
void gtk_main(void);