diff --git a/Library/MeasureScript.cpp b/Library/MeasureScript.cpp index 57108fa1..d75e44e2 100644 --- a/Library/MeasureScript.cpp +++ b/Library/MeasureScript.cpp @@ -54,6 +54,16 @@ void MeasureScript::UninitializeLuaScript() m_HasGetStringFunction = false; } +void MeasureScript::Initialize() +{ + Measure::Initialize(); + + if (m_LuaScript.IsFunction(g_InitializeFunctionName)) + { + m_LuaScript.RunFunction(g_InitializeFunctionName); + } +} + /* ** Runs the function "Update()" in the script. ** @@ -155,9 +165,11 @@ void MeasureScript::ReadOptions(ConfigParser& parser, const WCHAR* section) // Pop PROPERTIES table and our table lua_pop(L, 2); - if (hasInitializeFunction) + if (m_Initialized) { - m_LuaScript.RunFunction(g_InitializeFunctionName); + // If the measure is already initialized and the script has changed, we need to + // manually call Initialize(). + Initialize(); } // Valid script. diff --git a/Library/MeasureScript.h b/Library/MeasureScript.h index 6dafcc8f..c8c5daa4 100644 --- a/Library/MeasureScript.h +++ b/Library/MeasureScript.h @@ -35,6 +35,7 @@ public: void UninitializeLuaScript(); protected: + virtual void Initialize(); virtual void ReadOptions(ConfigParser& parser, const WCHAR* section); virtual void UpdateValue();