#include <PythonExecutor.hpp>
|
| errc_t | initialize () override |
| |
| void | finalize () override |
| |
| errc_t | execute (StringView script, ScriptResult *resultOut=nullptr) override |
| |
| errc_t | evaluate (StringView expression, ScriptResult *resultOut=nullptr) override |
| |
| std::string | getLastError () const override |
| |
| errc_t | setVariable (StringView name, StringView value) override |
| |
| errc_t | setVariable (StringView name, double value) override |
| |
| errc_t | setVariable (StringView name, int value) override |
| |
| errc_t | setVariable (StringView name, bool value) override |
| |
|
errc_t | setVariable (StringView name, const char *value) |
| |
| errc_t | getVariable (StringView name, std::string &value) const override |
| |
| errc_t | getVariable (StringView name, double &value) const override |
| |
| errc_t | getVariable (StringView name, int &value) const override |
| |
| errc_t | getVariable (StringView name, bool &value) const override |
| |
| virtual | ~ScriptExecutor ()=default |
| |
| errc_t | execute (StringView script, std::string *error) |
| |
|
errc_t | setVariable (Variable *var) |
| |
|
errc_t | getVariable (Variable *var) |
| |
|
|
std::string | captureError () const |
| |
|
|
PythonAPI * | api_ |
| |
|
PyObject * | globals_ {nullptr} |
| |
|
std::string | lastError_ |
| |
Python 脚本执行器
通过 PythonAPI 单例驱动 CPython 解释器, 多个 PythonExecutor 实例共享同一解释器状态。
◆ evaluate()
◆ execute()
执行脚本语句
- 参数
-
| script | 要执行的脚本语句 |
| resultOut | 执行结果指针,用于存储执行脚本语句的返回结果 |
- 注解
- 执行语句是否有返回值取决于脚本语言的设计,例如python执行语句没有返回值,而JavaScript、C、Ruby执行语句有返回值
- 返回
- 执行结果
实现了 ast::ScriptExecutor.
◆ finalize()
| void ast::PythonExecutor::finalize |
( |
| ) |
|
|
overridevirtual |
◆ getLastError()
| std::string ast::PythonExecutor::getLastError |
( |
| ) |
const |
|
overridevirtual |
获取最近一次执行脚本时的错误信息
- 警告
- 注意只能在execute函数执行失败后调用 不要通过调用该函数来判断脚本是否执行成功
- 返回
- 最近一次执行脚本时的错误信息
实现了 ast::ScriptExecutor.
◆ getVariable() [1/4]
| errc_t ast::PythonExecutor::getVariable |
( |
StringView | name, |
|
|
bool & | value ) const |
|
overridevirtual |
◆ getVariable() [2/4]
| errc_t ast::PythonExecutor::getVariable |
( |
StringView | name, |
|
|
double & | value ) const |
|
overridevirtual |
◆ getVariable() [3/4]
| errc_t ast::PythonExecutor::getVariable |
( |
StringView | name, |
|
|
int & | value ) const |
|
overridevirtual |
◆ getVariable() [4/4]
| errc_t ast::PythonExecutor::getVariable |
( |
StringView | name, |
|
|
std::string & | value ) const |
|
overridevirtual |
◆ initialize()
| errc_t ast::PythonExecutor::initialize |
( |
| ) |
|
|
overridevirtual |
◆ setVariable() [1/4]
| errc_t ast::PythonExecutor::setVariable |
( |
StringView | name, |
|
|
bool | value ) |
|
overridevirtual |
◆ setVariable() [2/4]
| errc_t ast::PythonExecutor::setVariable |
( |
StringView | name, |
|
|
double | value ) |
|
overridevirtual |
◆ setVariable() [3/4]
| errc_t ast::PythonExecutor::setVariable |
( |
StringView | name, |
|
|
int | value ) |
|
overridevirtual |
◆ setVariable() [4/4]
该类的文档由以下文件生成: