Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-08-31 07:21:32 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-08-31 07:21:32 +0300
commit98800aa4e0f7b4aa169e799e804b1ba658be6e69 (patch)
tree213282115533eca6c53d2c0f7bd864aec11b2e60 /source/blender/python/intern/bpy_interface.c
parent18d135d05c53885eb7460e1c95cc8ebbdb771102 (diff)
C/Python API: Add PyC_RunString_AsIntPtr
Utility to get an int or pointer from a Python expression.
Diffstat (limited to 'source/blender/python/intern/bpy_interface.c')
-rw-r--r--source/blender/python/intern/bpy_interface.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index c84765e9a47..66abc017fe1 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -655,6 +655,42 @@ bool BPY_execute_string_as_string(bContext *C, const char *expr, const bool verb
return ok;
}
+/**
+ * Support both int and pointers.
+ *
+ * \return success
+ */
+bool BPY_execute_string_as_intptr(bContext *C, const char *expr, const bool verbose, intptr_t *r_value)
+{
+ PyGILState_STATE gilstate;
+ bool ok = true;
+
+ if (!r_value || !expr) {
+ return -1;
+ }
+
+ if (expr[0] == '\0') {
+ *r_value = 0;
+ return ok;
+ }
+
+ bpy_context_set(C, &gilstate);
+
+ ok = PyC_RunString_AsIntPtr(expr, "<blender button>", r_value);
+
+ if (ok == false) {
+ if (verbose) {
+ BPy_errors_to_report_ex(CTX_wm_reports(C), false, false);
+ }
+ else {
+ PyErr_Clear();
+ }
+ }
+
+ bpy_context_clear(C, &gilstate);
+
+ return ok;
+}
bool BPY_execute_string_ex(bContext *C, const char *expr, bool use_eval)
{