From dbca576d5057290736e4f3ee81d52d5987580a3b Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 28 Sep 2011 19:52:28 +0000 Subject: [PATCH] Require that macros defined in a single script have unique names Originally committed to SVN as r5665. --- aegisub/src/auto4_lua.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index 6cea78157..f82af64aa 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -333,15 +333,25 @@ namespace Automation4 { Create(); } - void LuaScript::RegisterCommand(LuaCommand *command) { + void LuaScript::RegisterCommand(LuaCommand *command) + { + for (size_t i = 0; i < macros.size(); ++i) { + if (macros[i]->name() == command->name()) { + luaL_error(L, + "A macro named '%s' is already defined in script '%s'", + command->StrDisplay(0).utf8_str().data(), name.utf8_str().data()); + } + } macros.push_back(command); } - void LuaScript::UnregisterCommand(LuaCommand *command) { + void LuaScript::UnregisterCommand(LuaCommand *command) + { macros.erase(remove(macros.begin(), macros.end(), command), macros.end()); } - void LuaScript::RegisterFilter(LuaExportFilter *filter) { + void LuaScript::RegisterFilter(LuaExportFilter *filter) + { filters.push_back(filter); }