Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/intern/bpy_interface.c
| Show First 20 Lines • Show All 601 Lines • ▼ Show 20 Lines | if (error_ret) { | ||||
| } | } | ||||
| } | } | ||||
| bpy_context_clear(C, &gilstate); | bpy_context_clear(C, &gilstate); | ||||
| return error_ret; | return error_ret; | ||||
| } | } | ||||
| int BPY_string_exec(bContext *C, const char *expr) | int BPY_string_exec_ex(bContext *C, const char *expr, bool use_eval) | ||||
| { | { | ||||
| PyGILState_STATE gilstate; | PyGILState_STATE gilstate; | ||||
| PyObject *main_mod = NULL; | PyObject *main_mod = NULL; | ||||
| PyObject *py_dict, *retval; | PyObject *py_dict, *retval; | ||||
| int error_ret = 0; | int error_ret = 0; | ||||
| Main *bmain_back; /* XXX, quick fix for release (Copy Settings crash), needs further investigation */ | Main *bmain_back; /* XXX, quick fix for release (Copy Settings crash), needs further investigation */ | ||||
| if (!expr) return -1; | if (!expr) return -1; | ||||
| if (expr[0] == '\0') { | if (expr[0] == '\0') { | ||||
| return error_ret; | return error_ret; | ||||
| } | } | ||||
| bpy_context_set(C, &gilstate); | bpy_context_set(C, &gilstate); | ||||
| PyC_MainModule_Backup(&main_mod); | PyC_MainModule_Backup(&main_mod); | ||||
| py_dict = PyC_DefaultNameSpace("<blender string>"); | py_dict = PyC_DefaultNameSpace("<blender string>"); | ||||
| bmain_back = bpy_import_main_get(); | bmain_back = bpy_import_main_get(); | ||||
| bpy_import_main_set(CTX_data_main(C)); | bpy_import_main_set(CTX_data_main(C)); | ||||
| retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict); | retval = PyRun_String(expr, use_eval ? Py_eval_input : Py_file_input, py_dict, py_dict); | ||||
| bpy_import_main_set(bmain_back); | bpy_import_main_set(bmain_back); | ||||
| if (retval == NULL) { | if (retval == NULL) { | ||||
| error_ret = -1; | error_ret = -1; | ||||
| BPy_errors_to_report(CTX_wm_reports(C)); | BPy_errors_to_report(CTX_wm_reports(C)); | ||||
| } | } | ||||
| else { | else { | ||||
| Py_DECREF(retval); | Py_DECREF(retval); | ||||
| } | } | ||||
| PyC_MainModule_Restore(main_mod); | PyC_MainModule_Restore(main_mod); | ||||
| bpy_context_clear(C, &gilstate); | bpy_context_clear(C, &gilstate); | ||||
| return error_ret; | return error_ret; | ||||
| } | } | ||||
| int BPY_string_exec(bContext *C, const char *expr) | |||||
| { | |||||
| return BPY_string_exec_ex(C, expr, true); | |||||
| } | |||||
| void BPY_modules_load_user(bContext *C) | void BPY_modules_load_user(bContext *C) | ||||
| { | { | ||||
| PyGILState_STATE gilstate; | PyGILState_STATE gilstate; | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Text *text; | Text *text; | ||||
| /* can happen on file load */ | /* can happen on file load */ | ||||
| ▲ Show 20 Lines • Show All 249 Lines • Show Last 20 Lines | |||||