Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
daym opened this issue Oct 26, 2020 · 1 comment

Comments

@daym
Copy link

daym commented Oct 26, 2020

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;
}
@daym daym changed the title Leave cells off in GtkTreeStore Support GValue with type tag but unset-value-from-guile in order to get the glib-default value of that type Oct 26, 2020
@LordYuuma
Copy link
Collaborator

(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.

@daym daym closed this as completed Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants