5 #include <unordered_map>
14 using std::unordered_map;
26 for (
const auto& [scriptId, script]: scriptsById)
delete script;
30 void Context::addScript(
const string&
id,
MinitScript* script) {
32 if (scriptsById.find(
id) != scriptsById.end()) {
34 Console::printLine(
"An error occurred: a script with id " +
id +
" is already registered");
38 scriptsById[id] = script;
41 void Context::removeScript(
const string&
id) {
43 auto scriptsIt = scriptsById.find(
id);
44 if (scriptsIt == scriptsById.end()) {
45 Console::printLine(
"An error occurred: no script with id " +
id +
" is registered");
48 auto script = scriptsIt->second;
50 if (find(scriptCallStack.begin(), scriptCallStack.end(), script) != scriptCallStack.end()) {
52 Console::printLine(
"An error occurred: script with id " +
id +
" is currently in use");
57 scriptsById.erase(scriptsIt);