Created
April 7, 2014 22:49
-
-
Save ptomato/10070608 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p m4 | |
autoreconf -if |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dnl Process this file with autoconf to produce configure | |
AC_INIT([Foo], [0], [], [foo], []) | |
AC_CONFIG_SRCDIR([foobar.h]) | |
AM_INIT_AUTOMAKE([foreign 1.11]) | |
AM_SILENT_RULES([yes]) | |
LT_INIT([disable-static]) | |
AC_CONFIG_MACRO_DIR([m4]) | |
AC_PROG_CC | |
PKG_PROG_PKG_CONFIG | |
GOBJECT_INTROSPECTION_REQUIRE([1.39]) | |
PKG_CHECK_MODULES([FOO], [glib-2.0 gobject-2.0]) | |
AC_CONFIG_FILES([Makefile]) | |
AC_CONFIG_HEADERS([config.h]) | |
AC_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "foobar.h" | |
#include <glib.h> | |
G_DEFINE_TYPE (FooBar, foo_bar, G_TYPE_OBJECT); | |
enum { | |
PROP_0, | |
PROP_EMPTY_LIST, | |
PROP_FULL_LIST, | |
NPROPS | |
}; | |
static GParamSpec *foo_bar_props[NPROPS] = { NULL, }; | |
static void | |
foo_bar_get_property (GObject *object, | |
guint property_id, | |
GValue *value, | |
GParamSpec *pspec) | |
{ | |
FooBar *self = FOO_BAR (object); | |
switch (property_id) | |
{ | |
case PROP_EMPTY_LIST: | |
g_value_set_pointer (value, foo_bar_get_empty_list (self)); | |
break; | |
case PROP_FULL_LIST: | |
g_value_set_pointer (value, foo_bar_get_full_list (self)); | |
break; | |
default: | |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | |
} | |
} | |
static void | |
foo_bar_class_init (FooBarClass *klass) | |
{ | |
GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
object_class->get_property = foo_bar_get_property; | |
/** | |
* FooBar:empty-list: (type GList(GObject)): | |
* | |
* Empty list with no #GObject objects inside. | |
*/ | |
foo_bar_props[PROP_EMPTY_LIST] = | |
g_param_spec_pointer ("empty-list", "Empty list", "Empty list", | |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); | |
/** | |
* FooBar:full-list: (type GList(GObject)): | |
* | |
* List with some #GObject objects inside. | |
*/ | |
foo_bar_props[PROP_FULL_LIST] = | |
g_param_spec_pointer ("full-list", "Full list", "Full list", | |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); | |
g_object_class_install_properties (object_class, NPROPS, foo_bar_props); | |
} | |
static void | |
foo_bar_init (FooBar *self) | |
{ | |
} | |
/* PUBLIC API */ | |
/** | |
* foo_bar_new: | |
* | |
* Stub | |
* | |
* Returns: (transfer full): stub | |
*/ | |
FooBar * | |
foo_bar_new (void) | |
{ | |
return g_object_new (FOO_TYPE_BAR, NULL); | |
} | |
/** | |
* foo_bar_get_empty_list: | |
* @self: the foo bar | |
* | |
* Stub | |
* | |
* Returns: (transfer full) (element-type GObject): an empty list without any | |
* #GObject objects. | |
*/ | |
GList * | |
foo_bar_get_empty_list (FooBar *self) | |
{ | |
return NULL; | |
} | |
/** | |
* foo_bar_get_full_list: | |
* @self: the foo bar | |
* | |
* Stub | |
* | |
* Returns: (transfer full) (element-type GObject): a list of #GObject objects. | |
*/ | |
GList * | |
foo_bar_get_full_list (FooBar *self) | |
{ | |
GList *retval = NULL; | |
retval = g_list_prepend (retval, g_object_new (G_TYPE_OBJECT, NULL)); | |
retval = g_list_prepend (retval, g_object_new (G_TYPE_OBJECT, NULL)); | |
retval = g_list_prepend (retval, g_object_new (G_TYPE_OBJECT, NULL)); | |
return retval; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef FOO_BAR_H | |
#define FOO_BAR_H | |
#include <glib-object.h> | |
G_BEGIN_DECLS | |
#define FOO_TYPE_BAR foo_bar_get_type() | |
#define FOO_BAR(obj) \ | |
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \ | |
FOO_TYPE_BAR, FooBar)) | |
#define FOO_BAR_CLASS(klass) \ | |
(G_TYPE_CHECK_CLASS_CAST ((klass), \ | |
FOO_TYPE_BAR, FooBarClass)) | |
#define FOO_IS_BAR(obj) \ | |
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ | |
FOO_TYPE_BAR)) | |
#define FOO_IS_BAR_CLASS(klass) \ | |
(G_TYPE_CHECK_CLASS_TYPE ((klass), \ | |
FOO_TYPE_BAR)) | |
#define FOO_BAR_GET_CLASS(obj) \ | |
(G_TYPE_INSTANCE_GET_CLASS ((obj), \ | |
FOO_TYPE_BAR, FooBarClass)) | |
/** | |
* FooBar: | |
*/ | |
typedef struct _FooBar FooBar; | |
/** | |
* FooBarClass: | |
*/ | |
typedef struct _FooBarClass FooBarClass; | |
struct _FooBar | |
{ | |
/*< private >*/ | |
GObject parent; | |
}; | |
struct _FooBarClass | |
{ | |
/*< private >*/ | |
GObjectClass parent_class; | |
}; | |
GType foo_bar_get_type (void) G_GNUC_CONST; | |
FooBar *foo_bar_new (void); | |
GList *foo_bar_get_empty_list (FooBar *self); | |
GList *foo_bar_get_full_list (FooBar *self); | |
G_END_DECLS | |
#endif /* FOO_BAR_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Process this file with automake to produce Makefile.in | |
ACLOCAL_AMFLAGS = -I m4 | |
AM_CPPFLAGS = $(FOO_CFLAGS) | |
lib_LTLIBRARIES = libfoo.la | |
libfoo_la_SOURCES = foobar.c foobar.h | |
libfoo_la_LIBADD = $(FOO_LIBS) | |
libfoo_la_LDFLAGS = -export-symbols-regex "^foo_" | |
-include $(INTROSPECTION_MAKEFILE) | |
INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) --warn-all | |
INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir) | |
Foo-0.gir: libfoo.la | |
Foo_0_gir_INCLUDES = GObject-2.0 GLib-2.0 | |
Foo_0_gir_SCANNERFLAGS = --identifier-prefix=Foo --symbol-prefix=foo | |
Foo_0_gir_LIBS = libfoo.la | |
Foo_0_gir_FILES = foobar.c foobar.h | |
INTROSPECTION_GIRS = Foo-0.gir | |
girdir = $(datadir)/gir-1.0 | |
gir_DATA = $(INTROSPECTION_GIRS) | |
typelibdir = $(libdir)/girepository-1.0 | |
typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) | |
CLEANFILES = $(gir_DATA) $(typelib_DATA) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Foo = imports.gi.Foo; | |
let b = new Foo.Bar(); | |
print('Empty list property:'); | |
print(b.empty_list); | |
print('Empty list getter function:'); | |
print('[', b.get_empty_list(), ']'); | |
print('Full list property:'); | |
try { | |
print(b.full_list); | |
} catch (e) { | |
print(e); | |
} | |
print('Full list getter function:'); | |
print('[', b.get_full_list(), ']'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment