[template-glib] gi: allow accessing namespace children
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] gi: allow accessing namespace children
- Date: Mon, 23 Oct 2017 22:25:33 +0000 (UTC)
commit 93c5477fdf0858fd5ab8f1c660ae9c37dfefcda8
Author: Christian Hergert <chergert redhat com>
Date: Mon Oct 23 15:24:35 2017 -0700
gi: allow accessing namespace children
This allows you to access items within a namespace such as
"Gio.File". Further work is needed to be able to call methods
and such on the GIBaseInfo data.
src/tmpl-expr-eval.c | 32 ++++++++++++++++++++++++++++++++
src/tmpl-gi-private.h | 4 +++-
src/tmpl-gi.c | 3 ++-
3 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/src/tmpl-expr-eval.c b/src/tmpl-expr-eval.c
index 46d9c5e..78d9918 100644
--- a/src/tmpl-expr-eval.c
+++ b/src/tmpl-expr-eval.c
@@ -484,6 +484,38 @@ tmpl_expr_getattr_eval (TmplExprGetattr *node,
if (!tmpl_expr_eval_internal (node->left, scope, &left, error))
goto cleanup;
+ if (G_VALUE_HOLDS (&left, TMPL_TYPE_TYPELIB) &&
+ g_value_get_pointer (&left) != NULL)
+ {
+ GIRepository *repository = g_irepository_get_default ();
+ GITypelib *typelib = g_value_get_pointer (&left);
+ const gchar *ns = g_typelib_get_namespace (typelib);
+ GIBaseInfo *base_info;
+
+ /* Maybe we can resolve this dot accessor (.foo) using GObject
+ * Introspection from the first object.
+ */
+
+ base_info = g_irepository_find_by_name (repository, ns, node->attr);
+
+ if (base_info == NULL)
+ {
+ g_set_error (error,
+ TMPL_ERROR,
+ TMPL_ERROR_GI_FAILURE,
+ "Failed to locate %s within %s",
+ node->attr, ns);
+ goto cleanup;
+ }
+
+ g_value_init (return_value, TMPL_TYPE_BASE_INFO);
+ g_value_set_pointer (return_value, base_info);
+
+ ret = TRUE;
+
+ goto cleanup;
+ }
+
if (!G_VALUE_HOLDS_OBJECT (&left))
{
g_set_error (error,
diff --git a/src/tmpl-gi-private.h b/src/tmpl-gi-private.h
index d7cd8b1..7dbc311 100644
--- a/src/tmpl-gi-private.h
+++ b/src/tmpl-gi-private.h
@@ -21,9 +21,11 @@
G_BEGIN_DECLS
-#define TMPL_TYPE_TYPELIB (tmpl_typelib_get_type())
+#define TMPL_TYPE_TYPELIB (tmpl_typelib_get_type())
+#define TMPL_TYPE_BASE_INFO (tmpl_base_info_get_type())
GType tmpl_typelib_get_type (void);
+GType tmpl_base_info_get_type (void);
gboolean tmpl_gi_argument_from_g_value (const GValue *value,
GITypeInfo *type_info,
GIArgument *arg,
diff --git a/src/tmpl-gi.c b/src/tmpl-gi.c
index 35d8b5c..092fff1 100644
--- a/src/tmpl-gi.c
+++ b/src/tmpl-gi.c
@@ -20,7 +20,8 @@
#include "tmpl-error.h"
#include "tmpl-gi-private.h"
-G_DEFINE_POINTER_TYPE (GisTypelib, tmpl_typelib)
+G_DEFINE_POINTER_TYPE (TmplTypelib, tmpl_typelib)
+G_DEFINE_POINTER_TYPE (TmplBaseInfo, tmpl_base_info)
#define return_type_mismatch(value, type) \
G_STMT_START { \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]