CreatureLib/src/Battling/ScriptHandling/ScriptMacros.hpp

47 lines
5.1 KiB
C++
Raw Normal View History

#define HOOK(hookName, source, ...) \
{ \
try { \
auto aggregator = (source)->GetScriptIterator(); \
ArbUt::BorrowedPtr<CreatureLib::Battling::BattleScript> next; \
while (aggregator.GetNext(next)) { \
if (next->IsSuppressed()) { \
continue; \
} \
try { \
next->hookName(__VA_ARGS__); \
} catch (const std::exception& e) { \
2021-11-21 11:39:07 +00:00
THROW("Exception running script hook '" #hookName "': ", e.what()) \
} \
2020-07-31 12:17:38 +00:00
} \
} catch (const ArbUt::Exception& e) { \
throw e; \
} catch (const std::exception& e) { \
2021-11-21 11:39:07 +00:00
THROW("Exception setting up script hook '" #hookName "': ", e.what()) \
} \
}
#define EXECUTE_SCRIPT_FUNC(scriptWrapper, hookName, ...) \
{ \
try { \
if (scriptWrapper.HasValue()) { \
if (scriptWrapper.IsSet()) { \
for (const auto& scriptIterator : scriptWrapper.GetScriptSet()->GetIterator()) { \
if (scriptIterator->IsSuppressed()) { \
continue; \
} \
scriptIterator->hookName(__VA_ARGS__); \
} \
} else { \
if (scriptWrapper.GetScript()->get()->IsSuppressed()) { \
continue; \
} \
scriptWrapper.GetScript()->get()->hookName(__VA_ARGS__); \
} \
} \
} catch (const ArbUt::Exception& e) { \
throw e; \
} catch (const std::exception& e) { \
2021-11-21 11:39:07 +00:00
THROW("Exception setting up script hook '" #hookName "': ", e.what()) \
} \
}