diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-03-20 01:25:39 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-03-20 01:32:40 +0300 |
commit | 3f818c7898af20eed05b05e911a697a25287c432 (patch) | |
tree | 74715f36df2a0b26e6e4f52b7ed6d0e27316f336 /source/blender/python/intern | |
parent | 4137f30928dcfda4539d3d80df2c3e079eed12ec (diff) | |
parent | df76616d7450b99938f265283fad443186da4039 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/python/intern')
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 46 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_utils_units.c | 2 |
2 files changed, 43 insertions, 5 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 311f621e13b..55e477b0214 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -572,21 +572,58 @@ void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr) /** * \return success */ -bool BPY_execute_string_as_number(bContext *C, const char *expr, double *value, const bool verbose) +bool BPY_execute_string_as_number(bContext *C, const char *expr, const bool verbose, double *r_value) { PyGILState_STATE gilstate; bool ok = true; - if (!value || !expr) return -1; + if (!r_value || !expr) { + return -1; + } + + if (expr[0] == '\0') { + *r_value = 0.0; + return ok; + } + + bpy_context_set(C, &gilstate); + + ok = PyC_RunString_AsNumber(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; +} + +/** + * \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') { - *value = 0.0; + *r_value = NULL; return ok; } bpy_context_set(C, &gilstate); - ok = PyC_RunString_AsNumber(expr, value, "<blender button>"); + ok = PyC_RunString_AsString(expr, "<blender button>", r_value); if (ok == false) { if (verbose) { @@ -602,6 +639,7 @@ bool BPY_execute_string_as_number(bContext *C, const char *expr, double *value, return ok; } + bool BPY_execute_string_ex(bContext *C, const char *expr, bool use_eval) { PyGILState_STATE gilstate; diff --git a/source/blender/python/intern/bpy_utils_units.c b/source/blender/python/intern/bpy_utils_units.c index 974d7c5549c..e0c70483e3c 100644 --- a/source/blender/python/intern/bpy_utils_units.c +++ b/source/blender/python/intern/bpy_utils_units.c @@ -201,7 +201,7 @@ static PyObject *bpyunits_to_value(PyObject *UNUSED(self), PyObject *args, PyObj bUnit_ReplaceString(str, (int)str_len, uref, scale, usys, ucat); - if (!PyC_RunString_AsNumber(str, &result, "<bpy_units_api>")) { + if (!PyC_RunString_AsNumber(str, "<bpy_units_api>", &result)) { if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); |