gergelypolonkai-web-jekyll/_posts/2013-01-06-registering-an-e...

33 lines
1.4 KiB
Markdown
Raw Normal View History

2014-06-26 16:48:13 +00:00
---
layout: post
title: "Registering an enum type in GLibs type system"
2016-02-26 15:26:26 +00:00
date: 2013-01-06 02:34:03
2014-06-26 16:48:13 +00:00
tags: [c, development, glib]
permalink: /blog/2013/1/6/registering-an-enum-type-in-glib-s-type-system
published: true
author:
name: Gergely Polonkai
email: gergely@polonkai.eu
---
I faced a problem in my [GLib](https://developer.gnome.org/glib/) self-teaching
project, [wMUD](https://github.com/gergelypolonkai/wmud) today. I wanted to
register a signal for a `GObject`, whose handler should accept two `enum`
parameters for which I had to register a new `GEnum` type in the `GObject` type
system. However, the [documentation on this
feature](https://developer.gnome.org/gobject/unstable/gtype-non-instantiable.html)
(thanks for pointing out goes to hashem on `#gnome-hackers`) is not… uhm…
obvious. Making the long story short, I have checked with the `GIO` sources for
an example, and using that, I have created this small, working chunk:
2017-08-31 09:55:54 +00:00
{% gist 47794b6fb94484f8160b client-state.h %}
2014-06-26 16:48:13 +00:00
2017-08-31 09:55:54 +00:00
{% gist 47794b6fb94484f8160b client-state.c %}
2014-06-26 16:48:13 +00:00
Still, it can be made more perfect by using the
[glib-mkenums](http://developer.gnome.org/gobject/stable/glib-mkenums.html)
tool. I will read through the GLib Makefiles tomorrow for some hints on
this.
2015-04-27 09:09:15 +00:00
2017-08-31 09:55:54 +00:00
Edit: you can find the glib-mkenums solution [here]({% post_url 2014-08-16-registering-an-enum-type-in-glib-glib-mkenums-magic %}).