From c4fc54a83818a4b22099348bbdc512043c458f65 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Sun, 25 Jun 2006 07:01:33 -0500 Subject: [PATCH] Wrapped moo_plugin_call_method() --- moo/moopython/pygtk/mooedit-pygtk.override | 83 ++++++++++++++++++++++ moo/moopython/pygtk/mooplugin.defs | 4 +- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/moo/moopython/pygtk/mooedit-pygtk.override b/moo/moopython/pygtk/mooedit-pygtk.override index 84c6ba39..7d445c14 100644 --- a/moo/moopython/pygtk/mooedit-pygtk.override +++ b/moo/moopython/pygtk/mooedit-pygtk.override @@ -460,3 +460,86 @@ _wrap_moo_lang_mgr_get_available_langs (PyGObject *self) g_slist_free (list); return result; } +%% +override moo_plugin_call_method varargs +static PyObject * +_wrap_moo_plugin_call_method (PyGObject *self, PyObject *args) +{ + const char *name; + MooPluginMeth *meth; + GValue *params = NULL; + GValue retval; + PyObject *ret = NULL; + guint i; + + if (!args || !PyTuple_GET_SIZE (args)) + return_TypeErr ("Plugin.call_method takes at least 1 argument"); + + name = PyString_AsString (PyTuple_GET_ITEM (args, 0)); + + if (!name) + return NULL; + + meth = moo_plugin_lookup_method (self->obj, name); + + if (!meth) + { + PyErr_Format (PyExc_TypeError, "in Plugin.call_method: unknown method '%s'", name); + return NULL; + } + + if ((int) meth->n_params + 1 != PyTuple_GET_SIZE (args)) + { + PyErr_Format (PyExc_TypeError, "in Plugin.call_method: method '%s' takes " + "exactly %d arguments (%d given)", name, meth->n_params, + PyTuple_GET_SIZE (args) - 1); + return NULL; + } + + if (meth->return_type != G_TYPE_NONE) + { + retval.g_type = 0; + g_value_init (&retval, meth->return_type); + } + + params = g_new0 (GValue, meth->n_params + 1); + g_value_init (params, G_OBJECT_TYPE (self->obj)); + g_value_set_object (params, self->obj); + + for (i = 0; i < meth->n_params; ++i) + { + g_value_init (¶ms[i+1], meth->param_types[i]); + + if (pyg_value_from_pyobject (¶ms[i+1], PyTuple_GET_ITEM (args, i+1))) + { + PyObject *ps = PyObject_Str (PyTuple_GET_ITEM (args, i+1)); + char *s = PyString_AsString (ps); + PyErr_Format(PyExc_TypeError, "could not convert object '%s' to type '%s'", + s ? s : "(unknown)", g_type_name (meth->param_types[i])); + Py_XDECREF (ps); + goto out; + } + } + + moo_plugin_call_methodv (params, name, &retval); + + if (meth->return_type != G_TYPE_NONE) + { + ret = pyg_value_as_pyobject (&retval, TRUE); + } + else + { + ret = Py_None; + Py_INCREF (ret); + } + +out: + if (meth->return_type != G_TYPE_NONE) + g_value_unset (&retval); + for (i = 0; i < meth->n_params + 1; ++i) + if (G_IS_VALUE (¶ms[i])) + g_value_unset (¶ms[i]); + g_free (params); + + return ret; +} diff --git a/moo/moopython/pygtk/mooplugin.defs b/moo/moopython/pygtk/mooplugin.defs index 41e3c0be..9e60a161 100644 --- a/moo/moopython/pygtk/mooplugin.defs +++ b/moo/moopython/pygtk/mooplugin.defs @@ -141,8 +141,8 @@ (define-method call_method (of-object "MooPlugin") - (c-name "moo_plugin_lookup_method") - (return-type "MooPluginMeth*") + (c-name "moo_plugin_call_method") + (return-type "none") (parameters '("const-char*" "name") )