🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
ast::PythonExecutor类 参考

#include <PythonExecutor.hpp>

+ 类 ast::PythonExecutor 继承关系图:

Public 成员函数

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
 
- Public 成员函数 继承自 ast::ScriptExecutor
virtual ~ScriptExecutor ()=default
 
errc_t execute (StringView script, std::string *error)
 
errc_t setVariable (Variable *var)
 
errc_t getVariable (Variable *var)
 

Protected 成员函数

std::string captureError () const
 

Protected 属性

PythonAPIapi_
 
PyObject * globals_ {nullptr}
 
std::string lastError_
 

详细描述

Python 脚本执行器

通过 PythonAPI 单例驱动 CPython 解释器, 多个 PythonExecutor 实例共享同一解释器状态。

成员函数说明

◆ evaluate()

errc_t ast::PythonExecutor::evaluate ( StringView expression,
ScriptResult * resultOut = nullptr )
overridevirtual

对脚本表达式进行求值

参数
expression脚本表达式
resultOut执行结果指针,用于存储求值表达式时的结果
返回
求值结果

重载 ast::ScriptExecutor .

◆ execute()

errc_t ast::PythonExecutor::execute ( StringView script,
ScriptResult * resultOut = nullptr )
overridevirtual

执行脚本语句

参数
script要执行的脚本语句
resultOut执行结果指针,用于存储执行脚本语句的返回结果
注解
执行语句是否有返回值取决于脚本语言的设计,例如python执行语句没有返回值,而JavaScript、C、Ruby执行语句有返回值
返回
执行结果

实现了 ast::ScriptExecutor.

◆ finalize()

void ast::PythonExecutor::finalize ( )
overridevirtual

结束脚本执行器

结束脚本执行器,释放所有资源

实现了 ast::ScriptExecutor.

◆ 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

实现了 ast::ScriptExecutor.

◆ getVariable() [2/4]

errc_t ast::PythonExecutor::getVariable ( StringView name,
double & value ) const
overridevirtual

实现了 ast::ScriptExecutor.

◆ getVariable() [3/4]

errc_t ast::PythonExecutor::getVariable ( StringView name,
int & value ) const
overridevirtual

实现了 ast::ScriptExecutor.

◆ getVariable() [4/4]

errc_t ast::PythonExecutor::getVariable ( StringView name,
std::string & value ) const
overridevirtual

获取脚本执行器的字符串变量值

参数
name变量名称
value变量值
返回
获取结果

实现了 ast::ScriptExecutor.

◆ initialize()

errc_t ast::PythonExecutor::initialize ( )
overridevirtual

初始化脚本执行器

初始化脚本执行器,准备执行脚本

返回
初始化结果

实现了 ast::ScriptExecutor.

◆ setVariable() [1/4]

errc_t ast::PythonExecutor::setVariable ( StringView name,
bool value )
overridevirtual

实现了 ast::ScriptExecutor.

◆ setVariable() [2/4]

errc_t ast::PythonExecutor::setVariable ( StringView name,
double value )
overridevirtual

实现了 ast::ScriptExecutor.

◆ setVariable() [3/4]

errc_t ast::PythonExecutor::setVariable ( StringView name,
int value )
overridevirtual

实现了 ast::ScriptExecutor.

◆ setVariable() [4/4]

errc_t ast::PythonExecutor::setVariable ( StringView name,
StringView value )
overridevirtual

设置脚本执行器的变量

参数
name变量名称
value变量值
返回
设置结果

实现了 ast::ScriptExecutor.


该类的文档由以下文件生成: