Commit 93c5477f authored by Christian Hergert's avatar Christian Hergert

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.
parent 687febf8
......@@ -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,
......
......@@ -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,
......
......@@ -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 { \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment