Blender
V4.3
source
blender
freestyle
intern
system
PythonInterpreter.h
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
5
#pragma once
6
12
#include <iostream>
13
14
#include "
Interpreter.h
"
15
16
#include "
BKE_context.hh
"
17
#include "
BKE_global.hh
"
18
#include "
BKE_lib_id.hh
"
19
#include "
BKE_main.hh
"
20
#include "
BKE_text.h
"
21
22
#include "
BPY_extern_run.hh
"
23
24
#include "
bpy_capi_utils.hh
"
25
26
namespace
Freestyle
{
27
28
class
PythonInterpreter
:
public
Interpreter
{
29
public
:
30
PythonInterpreter
()
31
{
32
_language
=
"Python"
;
33
_context = 0;
34
memset(&_freestyle_bmain, 0,
sizeof
(
Main
));
35
}
36
37
void
setContext
(
bContext
*C)
38
{
39
_context =
C
;
40
}
41
42
int
interpretFile
(
const
string
&filename)
43
{
44
char
*fn =
const_cast<
char
*
>
(filename.c_str());
45
#if 0
46
bool
ok =
BPY_run_filepath
(_context, fn,
nullptr
);
47
#else
48
bool
ok;
49
Text
*text =
BKE_text_load
(&_freestyle_bmain, fn,
G_MAIN
->
filepath
);
50
if
(text) {
51
ok =
BPY_run_text
(_context, text,
nullptr
,
false
);
52
BKE_id_delete
(&_freestyle_bmain, text);
53
}
54
else
{
55
cerr <<
"Cannot open file"
<< endl;
56
ok =
false
;
57
}
58
#endif
59
60
if
(ok ==
false
) {
61
cerr <<
"\nError executing Python script from PythonInterpreter::interpretFile"
<< endl;
62
cerr <<
"File: "
<< fn << endl;
63
return
1;
64
}
65
66
return
0;
67
}
68
69
int
interpretString
(
const
string
&
str
,
const
string
&name)
70
{
71
if
(!
BPY_run_string_eval
(_context,
nullptr
,
str
.c_str())) {
72
cerr <<
"\nError executing Python script from PythonInterpreter::interpretString"
<< endl;
73
cerr <<
"Name: "
<< name << endl;
74
return
1;
75
}
76
77
return
0;
78
}
79
80
int
interpretText
(
struct
Text
*text,
const
string
&name)
81
{
82
if
(!
BPY_run_text
(_context, text,
nullptr
,
false
)) {
83
cerr <<
"\nError executing Python script from PythonInterpreter::interpretText"
<< endl;
84
cerr <<
"Name: "
<< name << endl;
85
return
1;
86
}
87
return
0;
88
}
89
90
void
reset
()
91
{
92
// nothing to do
93
}
94
95
private
:
96
bContext
*_context;
97
Main
_freestyle_bmain;
98
};
99
100
}
/* namespace Freestyle */
BKE_context.hh
BKE_global.hh
G_MAIN
#define G_MAIN
Definition
BKE_global.hh:351
BKE_lib_id.hh
BKE_id_delete
void BKE_id_delete(Main *bmain, void *idv) ATTR_NONNULL()
Definition
lib_id_delete.cc:369
BKE_main.hh
BKE_text.h
BKE_text_load
struct Text struct Text * BKE_text_load(struct Main *bmain, const char *filepath, const char *relbase) ATTR_NONNULL(1
BPY_extern_run.hh
BPY_run_text
bool bool BPY_run_text(bContext *C, Text *text, ReportList *reports, bool do_jump) ATTR_NONNULL(1
BPY_run_filepath
bool BPY_run_filepath(bContext *C, const char *filepath, ReportList *reports) ATTR_NONNULL(1
BPY_run_string_eval
bool BPY_run_string_eval(bContext *C, const char *imports[], const char *expr)
Definition
bpy_interface_run.cc:293
Interpreter.h
Base Class of all script interpreters.
C
#define C
Definition
RandGen.cpp:29
bpy_capi_utils.hh
Freestyle::Interpreter
Definition
Interpreter.h:22
Freestyle::Interpreter::_language
string _language
Definition
Interpreter.h:41
Freestyle::PythonInterpreter
Definition
PythonInterpreter.h:28
Freestyle::PythonInterpreter::interpretFile
int interpretFile(const string &filename)
Definition
PythonInterpreter.h:42
Freestyle::PythonInterpreter::PythonInterpreter
PythonInterpreter()
Definition
PythonInterpreter.h:30
Freestyle::PythonInterpreter::reset
void reset()
Definition
PythonInterpreter.h:90
Freestyle::PythonInterpreter::interpretString
int interpretString(const string &str, const string &name)
Definition
PythonInterpreter.h:69
Freestyle::PythonInterpreter::setContext
void setContext(bContext *C)
Definition
PythonInterpreter.h:37
Freestyle::PythonInterpreter::interpretText
int interpretText(struct Text *text, const string &name)
Definition
PythonInterpreter.h:80
str
#define str(s)
Definition
ffmpeg_codecs.cc:103
Freestyle
inherits from class Rep
Definition
AppCanvas.cpp:20
Main
Definition
BKE_main.hh:122
Main::filepath
char filepath[1024]
Definition
BKE_main.hh:136
Text
Definition
DNA_text_types.h:26
bContext
Definition
blenkernel/intern/context.cc:61
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0