spk121 / guile-gi

Bindings for GObject Introspection and libgirepository for Guile
GNU General Public License v3.0
58 stars 7 forks source link

Support GValue with type tag but unset-value-from-guile in order to get the glib-default value of that type #97

Closed daym closed 3 years ago

daym commented 3 years ago

Is it possible to use (make <GValue> #:type <GClosure>) in order to make it pass the type to use in the call to g_value_init, but not the value ? This would be in order to get the glib default value of that type.

(Also, I don't seem to get an error or warning message on (make <GValue> #:quoox 2) either. Is that on purpose?)

I want that in order to be able to leave cells off in a GtkTreeStore row (specifically to leave GClosure cells off) by having an empty but type-tagged GValue that I then set via tree-store:set. It's also possible to just not specify that cell on tree-store:set in the first place--but still, I think the handling of GValue here is maybe weird. Not sure, though.

C program to play with:

#include <gtk/gtk.h>

int main(int argc, char* argv[]) {
        GtkTreeIter iter;
        GValue values[2] = {G_VALUE_INIT, G_VALUE_INIT};
        gint columns[2];
        gtk_init(&argc, &argv);
        GtkTreeStore* store = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_CLOSURE);
        gtk_tree_store_append(store, &iter, NULL);
        g_value_init(&values[0], G_TYPE_STRING);
        //g_value_init(&values[1], G_TYPE_CLOSURE);   // toggle this
        columns[0] = 0;
        columns[1] = 1;
        gtk_tree_store_set_valuesv(store, &iter, columns, values, 2);
        gtk_main();
        return 0;
}
LordYuuma commented 3 years ago
(require "GObject")
(load-by-name "GObject" "Value")
(let ((v (value:init (make <GValue>) G_TYPE_INT)))
  (set! (v) 42))

Note, that value:init does copy the underlying value on return, but the following is also possible:

(let* ((v (make <GValue>))
       (v2 (value:init v G_TYPE_INT)))
  (set! (v) 42))

You will have to work around #96 though.