PyAPI: add optional imports to expression eval API

Avoids having to use `__import__` to access modules.
This commit is contained in:
2018-09-03 12:38:19 +10:00
parent 4bb8dba340
commit 7ff1750218
7 changed files with 62 additions and 30 deletions

View File

@@ -588,7 +588,9 @@ void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr)
/**
* \return success
*/
bool BPY_execute_string_as_number(bContext *C, const char *expr, const bool verbose, double *r_value)
bool BPY_execute_string_as_number(
bContext *C, const char *imports[],
const char *expr, const bool verbose, double *r_value)
{
PyGILState_STATE gilstate;
bool ok = true;
@@ -604,7 +606,7 @@ bool BPY_execute_string_as_number(bContext *C, const char *expr, const bool verb
bpy_context_set(C, &gilstate);
ok = PyC_RunString_AsNumber(expr, "<blender button>", r_value);
ok = PyC_RunString_AsNumber(imports, expr, "<expr as number>", r_value);
if (ok == false) {
if (verbose) {
@@ -623,7 +625,9 @@ bool BPY_execute_string_as_number(bContext *C, const char *expr, const bool verb
/**
* \return success
*/
bool BPY_execute_string_as_string(bContext *C, const char *expr, const bool verbose, char **r_value)
bool BPY_execute_string_as_string(
bContext *C, const char *imports[],
const char *expr, const bool verbose, char **r_value)
{
BLI_assert(r_value && expr);
PyGILState_STATE gilstate;
@@ -636,7 +640,7 @@ bool BPY_execute_string_as_string(bContext *C, const char *expr, const bool verb
bpy_context_set(C, &gilstate);
ok = PyC_RunString_AsString(expr, "<blender button>", r_value);
ok = PyC_RunString_AsString(imports, expr, "<expr as str>", r_value);
if (ok == false) {
if (verbose) {
@@ -657,7 +661,9 @@ bool BPY_execute_string_as_string(bContext *C, const char *expr, const bool verb
*
* \return success
*/
bool BPY_execute_string_as_intptr(bContext *C, const char *expr, const bool verbose, intptr_t *r_value)
bool BPY_execute_string_as_intptr(
bContext *C, const char *imports[],
const char *expr, const bool verbose, intptr_t *r_value)
{
BLI_assert(r_value && expr);
PyGILState_STATE gilstate;
@@ -670,7 +676,7 @@ bool BPY_execute_string_as_intptr(bContext *C, const char *expr, const bool verb
bpy_context_set(C, &gilstate);
ok = PyC_RunString_AsIntPtr(expr, "<blender button>", r_value);
ok = PyC_RunString_AsIntPtr(imports, expr, "<expr as intptr>", r_value);
if (ok == false) {
if (verbose) {