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

How to make a GListStore of fixnums / How to subclass GObject #48

Open
seigakaku opened this issue Nov 11, 2023 · 2 comments
Open

How to make a GListStore of fixnums / How to subclass GObject #48

seigakaku opened this issue Nov 11, 2023 · 2 comments

Comments

@seigakaku
Copy link

I have a situation where using a GtkStringList to maintain a tree view would be wasteful, as I have directly mapping indexes to an array. As far as I understand from the GTK documentation, GListStore items must be subclasses of GObject.Object, so to use integers, in C I would have to create a new GObject with my integer field, but I can't seem to find a way to do that in cl-gtk4.
This was mentioned in #27 but you ended up providing an alternative solution.
Perhaps my idea of subclassing GObject is suboptimal as well and there is a simpler way to use fixnums?

@bohonghuang
Copy link
Owner

Currently, although it should theoretically be possible to achieve through some MOP (Metaobject Protocol) tricks, subclassing a GObject class in Lisp is still quite difficult. This is because it would require re-implementing the macros that are present in C. Additionally, introducing MOP might require refactoring the object representation in cl-gobject-introspection because, at present, using type-of in Lisp cannot differentiate between different types of GObjects. Therefore, this would be a significant undertaking. At this stage, I believe using strings to fulfill your requirements is a good solution. Lisp provides prin1-to-string and read-from-string, which allow for easy conversion between strings and Lisp data structures as long as unreadable objects are not involved.

@seigakaku
Copy link
Author

I understand, strings work fine, I wanted to use integers merely as an optmization, but it's not a problem, thank you for your answer.

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