summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/helpers.h
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2021-02-13 23:03:54 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2021-02-13 23:03:54 (GMT)
commit6c898505ec8b018a32683feb7d5dc598390ec677 (patch)
tree34450721efaac691ea6da5d0b2a1e726ae343920 /plugins/pychrysalide/helpers.h
parentd67565b24c0ac7d12e8b1d3385ba45e72a8c3863 (diff)
Give access to the plugin interfaces from Python.
Diffstat (limited to 'plugins/pychrysalide/helpers.h')
-rw-r--r--plugins/pychrysalide/helpers.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/plugins/pychrysalide/helpers.h b/plugins/pychrysalide/helpers.h
index 72a5489..931be95 100644
--- a/plugins/pychrysalide/helpers.h
+++ b/plugins/pychrysalide/helpers.h
@@ -237,6 +237,58 @@ int convert_to_gdk_rgba(PyObject *, void *);
/* ----------------------- TRANSFERT DES VALEURS CONSTANTES ------------------------- */
+/**
+ * Aides à la traduction.
+ */
+
+#define ADD_FIELD_TRANSLATION(dict, name, attrib) \
+ ({ \
+ int __ret; \
+ bool __status; \
+ __ret = PyDict_SetItemString(dict, name, attrib); \
+ Py_DECREF(attrib); \
+ __status = (__ret == 0); \
+ __status; \
+ })
+
+
+#define TRANSLATE_BOOLEAN_FIELD(dict, base, field) \
+ ({ \
+ PyObject *__attrib; \
+ __attrib = (base->field ? Py_True : Py_False); \
+ Py_INCREF(__attrib); \
+ ADD_FIELD_TRANSLATION(dict, #field, __attrib); \
+ })
+
+
+#define TRANSLATE_STRING_FIELD(dict, base, field) \
+ ({ \
+ PyObject *__attrib; \
+ if (base->field != NULL) \
+ __attrib = PyUnicode_FromString(base->field); \
+ else \
+ { \
+ __attrib = Py_None; \
+ Py_INCREF(Py_None); \
+ } \
+ ADD_FIELD_TRANSLATION(dict, #field, __attrib); \
+ })
+
+
+#define TRANSLATE_ARRAY_FIELD(dict, base, field, array) \
+ ({ \
+ PyObject *__attrib; \
+ bool __status; \
+ __attrib = PyTuple_New(base->field ## _count); \
+ __status = ADD_FIELD_TRANSLATION(dict, #field, __attrib); \
+ if (__status) \
+ (*array) = __attrib; \
+ else \
+ (*array) = NULL; \
+ __status; \
+ })
+
+
/* Simplification d'un ajout de constante pour l'appelant */
#define add_const_to_group(d, n, v) \
({ \