Blender
V5.0
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
11
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
}
34
35
void
setContext
(
bContext
*C)
36
{
37
_context = C;
38
}
39
40
int
interpretFile
(
const
string
&filename)
41
{
42
char
*fn =
const_cast<
char
*
>
(filename.c_str());
43
#if 0
44
bool
ok =
BPY_run_filepath
(_context, fn,
nullptr
);
45
#else
46
bool
ok;
47
Text
*text =
BKE_text_load
(&_freestyle_bmain, fn,
G_MAIN
->filepath);
48
if
(text) {
49
ok =
BPY_run_text
(_context, text,
nullptr
,
false
);
50
BKE_id_delete
(&_freestyle_bmain, text);
51
}
52
else
{
53
cerr <<
"Cannot open file"
<< endl;
54
ok =
false
;
55
}
56
#endif
57
58
if
(ok ==
false
) {
59
cerr <<
"\nError executing Python script from PythonInterpreter::interpretFile"
<< endl;
60
cerr <<
"File: "
<< fn << endl;
61
return
1;
62
}
63
64
return
0;
65
}
66
67
int
interpretString
(
const
string
&
str
,
const
string
&
name
)
68
{
69
if
(!
BPY_run_string_eval
(_context,
nullptr
,
str
.c_str())) {
70
cerr <<
"\nError executing Python script from PythonInterpreter::interpretString"
<< endl;
71
cerr <<
"Name: "
<<
name
<< endl;
72
return
1;
73
}
74
75
return
0;
76
}
77
78
int
interpretText
(
struct
Text
*text,
const
string
&
name
)
79
{
80
if
(!
BPY_run_text
(_context, text,
nullptr
,
false
)) {
81
cerr <<
"\nError executing Python script from PythonInterpreter::interpretText"
<< endl;
82
cerr <<
"Name: "
<<
name
<< endl;
83
return
1;
84
}
85
return
0;
86
}
87
88
void
reset
()
89
{
90
// nothing to do
91
}
92
93
private
:
94
bContext
*_context =
nullptr
;
95
Main
_freestyle_bmain = {};
96
};
97
98
}
/* namespace Freestyle */
BKE_context.hh
BKE_global.hh
G_MAIN
#define G_MAIN
Definition
BKE_global.hh:366
BKE_lib_id.hh
BKE_id_delete
void BKE_id_delete(Main *bmain, void *idv) ATTR_NONNULL()
Definition
lib_id_delete.cc:395
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:294
Interpreter.h
Base Class of all script interpreters.
bpy_capi_utils.hh
Freestyle::Interpreter::Interpreter
Interpreter()
Definition
Interpreter.h:22
Freestyle::Interpreter::_language
string _language
Definition
Interpreter.h:39
Freestyle::PythonInterpreter::interpretFile
int interpretFile(const string &filename)
Definition
PythonInterpreter.h:40
Freestyle::PythonInterpreter::PythonInterpreter
PythonInterpreter()
Definition
PythonInterpreter.h:30
Freestyle::PythonInterpreter::reset
void reset()
Definition
PythonInterpreter.h:88
Freestyle::PythonInterpreter::interpretString
int interpretString(const string &str, const string &name)
Definition
PythonInterpreter.h:67
Freestyle::PythonInterpreter::setContext
void setContext(bContext *C)
Definition
PythonInterpreter.h:35
Freestyle::PythonInterpreter::interpretText
int interpretText(struct Text *text, const string &name)
Definition
PythonInterpreter.h:78
str
#define str(s)
Definition
ffmpeg_codecs.cc:103
Freestyle
inherits from class Rep
Definition
AppCanvas.cpp:20
name
const char * name
Definition
python_compat.hh:32
Main
Definition
BKE_main.hh:160
Text
Definition
DNA_text_types.h:26
bContext
Definition
blenkernel/intern/context.cc:63
Generated on
for Blender by
doxygen
1.16.1