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.
This commit is contained in:
2017-03-18 12:19:03 +11:00
parent d863b5182e
commit e392bb4937
4 changed files with 75 additions and 0 deletions

View File

@@ -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;