Debian Codegraph @

include/iscript.h

raw
1 #pragma once
2
3 #include "imodule.h"
4 #include <sigc++/signal.h>
5
6 namespace script
7 {
8
9 struct ExecutionResult
10 {
11 // The output of the script
12 std::string output;
13
14 // whether an error occurred
15 bool errorOccurred;
16 };
17 typedef std::shared_ptr<ExecutionResult> ExecutionResultPtr;
18
19 // Declared in iscriptinterface.h
20 class IScriptInterface;
21 typedef std::shared_ptr<IScriptInterface> IScriptInterfacePtr;
22
23 // Represents a named, executable .py script file
24 class IScriptCommand
25 {
26 public:
27 virtual ~IScriptCommand() {}
28
29 virtual const std::string& getName() const = 0;
30 virtual const std::string& getFilename() const = 0;
31 virtual const std::string& getDisplayName() const = 0;
32 };
33
34 /**
35 * DarkRadiant's Scripting System, based on pybind11. It's possible
36 * to expose additional interfaces by using the addInterface() method.
37 */
38 class IScriptingSystem :
39 public RegisterableModule
40 {
41 public:
42 /**
43 * greebo: Add a named interface to the scripting system. The interface object
44 * must provide a "registerInterface" method which will declare the names
45 * and objects to the given namespace.
46 */
47 virtual void addInterface(const std::string& name, const IScriptInterfacePtr& iface) = 0;
48
49 /**
50 * greebo: Executes the given python script file. The filename is specified relatively
51 * to the scripts/ folder.
52 */
53 virtual void executeScriptFile(const std::string& filename) = 0;
54
55 /**
56 * greebo: Interprets the given string as python script.
57 *
58 * @returns: the result object.
59 */
60 virtual script::ExecutionResultPtr executeString(const std::string& scriptString) = 0;
61
62 /**
63 * Iterate over all available script commands, invoking the given functor.
64 */
65 virtual void foreachScriptCommand(const std::function<void(const IScriptCommand&)>& functor) = 0;
66
67 /**
68 * Signal fired when the available set of scripts has been reloaded
69 */
70 virtual sigc::signal<void>& signal_onScriptsReloaded() = 0;
71 };
72 typedef std::shared_ptr<IScriptingSystem> IScriptingSystemPtr;
73
74 } // namespace script
75
76 // String identifier for the script module
77 const char* const MODULE_SCRIPTING_SYSTEM("ScriptingSystem");
78
79 // This is the accessor for the scripting system
80 inline script::IScriptingSystem& GlobalScriptingSystem()
81 {
82 static module::InstanceReference<script::IScriptingSystem> _reference(MODULE_SCRIPTING_SYSTEM);
83 return _reference;
84 }