/
scriptsystem.h
146 lines (122 loc) · 4.28 KB
/
scriptsystem.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/** @file scriptsystem.h Subsystem for the scripts.
*
* @authors Copyright © 2013-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef LIBCORE_SCRIPTSYSTEM_H
#define LIBCORE_SCRIPTSYSTEM_H
#include "../Error"
#include "../System"
#include "../Record"
#include "../File"
namespace de {
/**
* App subsystem for running scripts.
*
* @ingroup script
*/
class DE_PUBLIC ScriptSystem : public System
{
public:
/// The module or script that was being looked for was not found. @ingroup errors
DE_ERROR(NotFoundError);
public:
ScriptSystem();
~ScriptSystem();
/**
* Specifies an additional path where modules may be imported from.
* "Config.importPath" is checked before any of the paths specified using this
* method.
*
* Paths specified using this method are not saved persistently in Config.
*
* @param path Additional module import path.
*/
void addModuleImportPath(Path const &path);
void removeModuleImportPath(Path const &path);
/**
* Adds a native module to the set of modules that can be imported in
* scripts.
*
* @param name Name of the module.
* @param module Module namespace. App will observe this for deletion.
*/
void addNativeModule(String const &name, Record &module);
void removeNativeModule(String const &name);
bool nativeModuleExists(const String &name) const;
Record &nativeModule(String const &name);
/**
* Returns a native or an imported module.
*
* @param name Name of the module.
*
* @return Module namespace.
*/
Record &operator[](const String &nativeModuleName);
/**
* Returns a list of the names of all the existing native modules.
*
* @return List of module names.
*/
StringList nativeModules() const;
/**
* Imports a script module that is located on the import path.
*
* @param name Name of the module.
* @param importedFromPath Absolute path of the script doing the importing.
*
* @return The imported module.
*/
Record &importModule(String const &name, String const &importedFromPath = "");
/**
* Looks for the source file of a module.
*
* @param name Name of the module to look for.
* @param localPath Which absolute path to use as the local folder (as import path "").
*
* @return Found source file, or @c NULL.
*/
File const *tryFindModuleSource(String const &name, String const &localPath = "");
/**
* Looks for the source file of a module.
*
* @param name Name of the module to look for.
* @param localPath Which absolute path to use as the local folder (as import path "").
*
* @return Found source file.
*/
File const &findModuleSource(String const &name, String const &localPath = "");
void timeChanged(Clock const &);
public:
/**
* Returns a built-in Doomsday Script class from the Core module.
* @param name Name of the class.
* @return Class record.
*/
static Record &builtInClass(String const &name);
/**
* Returns a built-in Doomsday Script class from the specified module.
* @param nativeModuleName Name of the module where the class is located.
* @param className Name of the class.
* @return Class record.
*/
static Record &builtInClass(String const &nativeModuleName,
String const &className);
static ScriptSystem &get();
private:
DE_PRIVATE(d)
};
} // namespace de
#endif // LIBCORE_SCRIPTSYSTEM_H