diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-03-18 04:19:03 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-03-18 04:19:03 +0300 |
commit | e392bb49372a76cb4abd7d64d73e37f9c7fcb806 (patch) | |
tree | 1d4a1f3dadf28d8f897ee87c70cfe4be462fdb2b /source/blender/python/intern/bpy_interface.c | |
parent | d863b5182e911b63f874c075f6c24a4c5933811e (diff) |
PyAPI: add BPY_execute_string_as_string
Utility to execute a string and get the resulting string,
matching BPY_execute_string_as_number.
Not used just yet but generally useful function.
Diffstat (limited to 'source/blender/python/intern/bpy_interface.c')
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 36 |
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 1d561517eab..55e477b0214 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -604,6 +604,42 @@ bool BPY_execute_string_as_number(bContext *C, const char *expr, const bool verb return ok; } +/** + * \return success + */ +bool BPY_execute_string_as_string(bContext *C, const char *expr, const bool verbose, char **r_value) +{ + PyGILState_STATE gilstate; + bool ok = true; + + if (!r_value || !expr) { + return -1; + } + + if (expr[0] == '\0') { + *r_value = NULL; + return ok; + } + + bpy_context_set(C, &gilstate); + + ok = PyC_RunString_AsString(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) { PyGILState_STATE gilstate; |