From 1760e42e2caa99d3de0038d1b52f64a1daeb665a Mon Sep 17 00:00:00 2001 From: QAston Date: Fri, 8 Oct 2010 21:33:44 +0200 Subject: Core/ScriptSystem: Add compile time type check of function assigned to hooks - prevents incorrect function calls. Since this rev you have to put PrepareSpellScript() at the beginning of every spell script. Yes, i know it's unhandy, but unfortunately C++ preprocessor is very limited, so you have to do that extra work each time you write a script:(. --HG-- branch : trunk --- src/server/scripts/Examples/example_spell.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/server/scripts/Examples') diff --git a/src/server/scripts/Examples/example_spell.cpp b/src/server/scripts/Examples/example_spell.cpp index 42126c953c3..5397cd161d8 100644 --- a/src/server/scripts/Examples/example_spell.cpp +++ b/src/server/scripts/Examples/example_spell.cpp @@ -33,6 +33,10 @@ class spell_ex_5581 : public SpellScriptLoader class spell_ex_5581SpellScript : public SpellScript { + // initialize script, this macro does compile time check for type of the function - prevents possible issues + // if you have assigned wrong type of function to a hook you'll receive type conversion error during build + // this line is required, otherwise you'll get XXXHandlerFunction - identifier not found errors + PrepareSpellScript(spell_ex_5581SpellScript) enum Spells { SPELL_TRIGGERED = 18282 @@ -100,6 +104,7 @@ class spell_ex_5581 : public SpellScriptLoader { // we're registering our function here // function HandleDummy will be called when unit is hit by spell, just before default effect 0 handler + //OnEffect += SpellEffectFn(spell_ex_5581SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY); OnEffect += SpellEffectFn(spell_ex_5581SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY); // this will prompt an error on startup because effect 0 of spell 49375 is set to SPELL_EFFECT_DUMMY, not SPELL_EFFECT_APPLY_AURA //OnEffect += SpellEffectFn(spell_gen_49375SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_APPLY_AURA); @@ -265,6 +270,7 @@ class spell_ex : public SpellScriptLoader class spell_ex_SpellScript : public SpellScript { + PrepareSpellScript(spell_ex_SpellScript) //bool Validate(SpellEntry const * spellEntry){return true;} //bool Load(){return true;} //void Unload(){} -- cgit v1.2.3