🛰️航天仿真算法库 SpaceAST 0.3.1
载入中...
搜索中...
未找到
ActiveScriptExecutor.hpp
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "ScriptExecutor.hpp"
25#include <memory>
26
27
28struct IDispatch;
29typedef struct tagVARIANT VARIANT;
30
31
32AST_NAMESPACE_BEGIN
33
39#if defined(AST_BUILD_LIB) && !defined(SWIG)
40errc_t aActiveScriptGetVariable(IDispatch& pDisp, const std::wstring& name, VARIANT& result);
41errc_t aActiveScriptSetVariable(IDispatch& pDisp, const std::wstring& name, const VARIANT& value);
42errc_t aActiveScriptSetVariableEx(IDispatch& pDisp, const std::wstring& name, const VARIANT& value);
43bool aActiveScriptHasVariable(IDispatch& pDisp, const std::wstring& name);
44#endif
45
49class AST_SCRIPT_API ActiveScriptExecutor: public ScriptExecutor
50{
51 // 前向声明内部实现类
52 class Impl;
53
54public:
55 using ScriptExecutor::execute;
56
61 explicit ActiveScriptExecutor(const wchar_t* progId);
62 ~ActiveScriptExecutor() override;
63
64 errc_t initialize() override;
65 void finalize() override;
66 errc_t execute(StringView script, ScriptResult* resultOut=nullptr) override;
67 errc_t evaluate(StringView expression, ScriptResult* resultOut=nullptr) override;
68 std::string getLastError() const override;
69
70 // 下面这些重载会隐藏基类同名的其他重载(含字符串字面量重载),需要显式引回
71 using ScriptExecutor::setVariable;
72
73 errc_t setVariable(StringView name, StringView value) override;
74 errc_t setVariable(StringView name, double value) override;
75 errc_t setVariable(StringView name, int value) override;
76 errc_t setVariable(StringView name, bool value) override;
77
78 errc_t getVariable(StringView name, std::string& value) const override;
79 errc_t getVariable(StringView name, double& value) const override;
80 errc_t getVariable(StringView name, int& value) const override;
81 errc_t getVariable(StringView name, bool& value) const override;
82
83protected:
85 void setProgID(const wchar_t* progId);
86
88 IDispatch* getGlobal() const;
89protected:
90 std::unique_ptr<Impl> impl_; // 隐藏 COM 对象与状态
91};
92
95AST_NAMESPACE_END
定义 ActiveScriptExecutor.cpp:31
微软Active系列脚本执行器
定义 ActiveScriptExecutor.hpp:50
IDispatch * getGlobal() const
获取脚本的全局根对象
void setProgID(const wchar_t *progId)
设置脚本引擎 ProgID(由子类如 JScriptExecutor 在构造时调用)
脚本执行器,用于执行外部脚本
定义 ScriptExecutor.hpp:81
virtual std::string getLastError() const =0
获取最近一次执行脚本时的错误信息
virtual errc_t execute(StringView script, ScriptResult *resultOut=nullptr)=0
执行脚本语句
virtual errc_t initialize()=0
初始化脚本执行器
virtual errc_t setVariable(StringView name, StringView value)=0
设置脚本执行器的变量
virtual errc_t evaluate(StringView expression, ScriptResult *resultOut=nullptr)
对脚本表达式进行求值
定义 ScriptExecutor.cpp:111
virtual errc_t getVariable(StringView name, std::string &value) const =0
获取脚本执行器的字符串变量值
virtual void finalize()=0
结束脚本执行器
脚本执行结果
定义 ScriptExecutor.hpp:65