Blender
V3.3
|
Go to the source code of this file.
Classes | |
struct | BPy_RunErrInfo |
Functions | |
Run File/Text as a Script | |
| |
bool | BPY_run_filepath (struct bContext *C, const char *filepath, struct ReportList *reports) ATTR_NONNULL(1 |
bool bool | BPY_run_text (struct bContext *C, struct Text *text, struct ReportList *reports, bool do_jump) ATTR_NONNULL(1 |
Run a String as a Script | |
| |
bool | BPY_run_string_exec (struct bContext *C, const char *imports[], const char *expr) |
bool | BPY_run_string_eval (struct bContext *C, const char *imports[], const char *expr) |
Run a String as a Script & Return the Result | |
Convenience functions for executing a script and returning the result as an expected type. | |
bool | BPY_run_string_as_number (struct bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, double *r_value) ATTR_NONNULL(1 |
bool bool | BPY_run_string_as_intptr (struct bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, intptr_t *r_value) ATTR_NONNULL(1 |
bool bool bool | BPY_run_string_as_string_and_size (struct bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, char **r_value, size_t *r_value_size) ATTR_NONNULL(1 |
bool bool bool bool | BPY_run_string_as_string (struct bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, char **r_value) ATTR_NONNULL(1 |
C
the bContext (never NULL).imports
: This is simply supported for convenience since imports can make constructing strings more cumbersome as otherwise small expressions become multi-line code-blocks. Optional (ignored when NULL), otherwise this is a NULL terminated array of module names.
Failure to import any modules prevents any further execution.
err_info
BPy_RunErrInfo is passed to some functions so errors can be forwarded to the UI. Option (when NULL errors are printed to the stdout
and cleared). However this should be used in any case the error would be useful to show to the user. Definition in file BPY_extern_run.h.
bool BPY_run_filepath | ( | struct bContext * | C, |
const char * | filepath, | ||
struct ReportList * | reports | ||
) |
Execute filepath
as a Python script.
Wrapper for PyRun_File
(similar to calling python with a script argument). Used for the --python
command line argument.
C | The context (never NULL). |
filepath | The file path to execute. |
reports | Failure to execute the script will report the exception here (may be NULL). |
reports
.bpy.utils.execfile
, which has the advantage of returning the object as a module for data access & caching pyc
file for faster re-execution. Referenced by arg_handle_python_file_run(), Freestyle::PythonInterpreter::interpretFile(), and run_pyfile_exec().
bool bool BPY_run_string_as_intptr | ( | struct bContext * | C, |
const char * | imports[], | ||
const char * | expr, | ||
struct BPy_RunErrInfo * | err_info, | ||
intptr_t * | r_value | ||
) |
Evaluate expr
as an integer or pointer.
C | See Common Arguments. |
imports | See Common Arguments. |
expr | The expression to evaluate. |
err_info | See Common Arguments. |
r_value | The resulting value. |
Referenced by ui_tooltip_data_from_tool().
bool BPY_run_string_as_number | ( | struct bContext * | C, |
const char * | imports[], | ||
const char * | expr, | ||
struct BPy_RunErrInfo * | err_info, | ||
double * | r_value | ||
) |
Evaluate expr
as a number (double).
C | See Common Arguments. |
imports | See Common Arguments. |
expr | The expression to evaluate. |
err_info | See Common Arguments. |
r_value | The resulting value. |
Referenced by ui_number_from_string(), and user_string_to_number().
bool bool bool bool BPY_run_string_as_string | ( | struct bContext * | C, |
const char * | imports[], | ||
const char * | expr, | ||
struct BPy_RunErrInfo * | err_info, | ||
char ** | r_value | ||
) |
See BPY_run_string_as_string_and_size
Referenced by ui_but_user_menu_add(), and ui_tooltip_data_from_tool().
bool bool bool BPY_run_string_as_string_and_size | ( | struct bContext * | C, |
const char * | imports[], | ||
const char * | expr, | ||
struct BPy_RunErrInfo * | err_info, | ||
char ** | r_value, | ||
size_t * | r_value_size | ||
) |
Evaluate expr
as a string.
C | See Common Arguments. |
imports | See Common Arguments. |
expr | The expression to evaluate. |
err_info | See Common Arguments. |
r_value | The resulting value. |
Referenced by ui_tooltip_data_from_tool().
Run an expression, matches: exec(compile(..., "eval"))
.
Definition at line 302 of file bpy_interface_run.c.
References bpy_run_string_impl(), and C.
Referenced by arg_handle_python_console_run(), BPY_python_start(), Freestyle::PythonInterpreter::interpretString(), script_reload_exec(), WM_exit_ex(), wm_file_read_post(), wm_homefile_read_ex(), and WM_keyconfig_reload().
Run an entire script, matches: exec(compile(..., "exec"))
Definition at line 307 of file bpy_interface_run.c.
References bpy_run_string_impl(), and C.
Referenced by arg_handle_addons_set(), arg_handle_python_expr_run(), script_reload_exec(), and wm_file_read_post().
bool bool BPY_run_text | ( | struct bContext * | C, |
struct Text * | text, | ||
struct ReportList * | reports, | ||
bool | do_jump | ||
) |
Execute a Blender text
block as a Python script.
Wrapper for Py_CompileStringObject
& PyEval_EvalCode
. Used for the --python-text
command line argument.
C | The context (never NULL). |
text | The text-block to execute. |
reports | Failure to execute the script will report the exception here (may be NULL). |
do_jump | When true, any error moves the cursor to the location of that error. Useful for executing scripts interactively from the text editor. |
reports
.__file__
is constructed by joining the blend file-path to the name of the text. This is done so error messages give useful output however there are rare cases causes problems with introspection tools which attempt to load __file__
. Referenced by arg_handle_python_text_run(), BPY_modules_load_user(), Freestyle::PythonInterpreter::interpretFile(), Freestyle::PythonInterpreter::interpretText(), and text_run_script().