For the Nim version of GTK 3.18 example application10 I have this code
https://github.com/StefanSalewski/nim-gtk3/tree/master/test/application10
I was able to avoid nealy all casts and addr operators, but in following code there are still two. Ideas to remove them?
var app_entries = [
gio.GActionEntryObj(name: "preferences", activate: preferences_activated, parameter_type: nil, state: nil, change_state: nil),
gio.GActionEntryObj(name: "quit", activate: quit_activated, parameter_type: nil, state: nil, change_state: nil)]
proc example_app_startup(app: gio.GApplication) {.cdecl.} =
var
builder: Builder
app_menu: gio.GMenuModel
quit_accels = [cstring "<Ctrl>Q", nil]
g_application_class(example_app_parent_class).startup(app)
add_action_entries(gio.g_action_map(app), addr app_entries[0], gint(len(app_entries)), app)
set_accels_for_action(application(app), "app.quit",
cast[cstringArray](addr quit_accels))
For original C this was
static GActionEntry app_entries[] = { { "preferences", preferences_activated, NULL, NULL, NULL }, { "quit", quit_activated, NULL, NULL, NULL } }; static void example_app_startup (GApplication *app) { GtkBuilder *builder; GMenuModel *app_menu; const gchar *quit_accels[2] = { "<Ctrl>Q", NULL }; G_APPLICATION_CLASS (example_app_parent_class)->startup (app); g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), app); gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.quit", quit_accels);
And a related question:
var text: cstring
if text[0] == '\0': return
Is there a more elegant way to test for empty cstring? I may prefer something like text[0] == "" if that works. Or may something like text.empty exist?
And a related question
system.nim doesn't really try to make cstring convenient to use.