/
iscript.h
75 lines (64 loc) · 1.99 KB
/
iscript.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include "imodule.h"
#include <boost/python/object_fwd.hpp>
namespace script
{
struct ExecutionResult
{
// The output of the script
std::string output;
// whether an error occurred
bool errorOccurred;
};
typedef std::shared_ptr<ExecutionResult> ExecutionResultPtr;
} // namespace script
class IScriptInterface
{
public:
virtual ~IScriptInterface() {}
/**
* This method gets invoked by the Scripting System to let this class
* add its interface to the Python context.
*/
virtual void registerInterface(boost::python::object& nspace) = 0;
};
typedef std::shared_ptr<IScriptInterface> IScriptInterfacePtr;
/**
* DarkRadiant's Scripting System, based on boost::python. It's possible
* to expose additional interfaces by using the addInterface() method.
*/
class IScriptingSystem :
public RegisterableModule
{
public:
/**
* greebo: Add a named interface to the scripting system. The interface object
* must provide a "registerInterface" method which will declare the names
* and objects to the given namespace.
*/
virtual void addInterface(const std::string& name, const IScriptInterfacePtr& iface) = 0;
/**
* greebo: Executes the given python script file. The filename is specified relatively
* to the scripts/ folder.
*/
virtual void executeScriptFile(const std::string& filename) = 0;
/**
* greebo: Interprets the given string as python script.
*
* @returns: the result object.
*/
virtual script::ExecutionResultPtr executeString(const std::string& scriptString) = 0;
};
typedef std::shared_ptr<IScriptingSystem> IScriptingSystemPtr;
// String identifier for the script module
const std::string MODULE_SCRIPTING_SYSTEM("ScriptingSystem");
// This is the accessor for the scripting system
inline IScriptingSystem& GlobalScriptingSystem() {
// Cache the reference locally
static IScriptingSystem& _scriptingSystem(
*std::static_pointer_cast<IScriptingSystem>(
module::GlobalModuleRegistry().getModule(MODULE_SCRIPTING_SYSTEM)
)
);
return _scriptingSystem;
}