From a0a0c61e79e8dfe97fd5921a31288870b6fda18c Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Wed, 18 Jul 2012 17:41:28 +0300 Subject: [PATCH] Script: Fixed that Initialize() was not called when the script is changed dynamically --- Library/MeasureScript.cpp | 23 ++++++----------------- Library/MeasureScript.h | 2 -- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/Library/MeasureScript.cpp b/Library/MeasureScript.cpp index 9dfb0ad2..eca8a0a7 100644 --- a/Library/MeasureScript.cpp +++ b/Library/MeasureScript.cpp @@ -30,7 +30,6 @@ const char* g_GetStringFunctionName = "GetStringValue"; */ CMeasureScript::CMeasureScript(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name), m_LuaScript(), - m_HasInitializeFunction(false), m_HasUpdateFunction(false), m_HasGetStringFunction(false), m_ValueType(LUA_TNIL) @@ -53,27 +52,12 @@ void CMeasureScript::DeleteLuaScript() delete m_LuaScript; m_LuaScript = NULL; - m_HasInitializeFunction = false; m_HasUpdateFunction = false; m_HasGetStringFunction = false; m_ScriptFile.clear(); } -/* -** Initializes the measure. -** -*/ -void CMeasureScript::Initialize() -{ - CMeasure::Initialize(); - - if (m_HasInitializeFunction) - { - m_LuaScript->RunFunction(g_InitializeFunctionName); - } -} - /* ** Updates the current disk free space value. ** @@ -134,7 +118,7 @@ void CMeasureScript::ReadOptions(CConfigParser& parser, const WCHAR* section) if (m_LuaScript->IsInitialized()) { - m_HasInitializeFunction = m_LuaScript->IsFunction(g_InitializeFunctionName); + bool hasInitializeFunction = m_LuaScript->IsFunction(g_InitializeFunctionName); m_HasUpdateFunction = m_LuaScript->IsFunction(g_UpdateFunctionName); m_HasGetStringFunction = m_LuaScript->IsFunction(g_GetStringFunctionName); // For backwards compatbility @@ -180,6 +164,11 @@ void CMeasureScript::ReadOptions(CConfigParser& parser, const WCHAR* section) // Pop PROPERTIES table and our table lua_pop(L, 2); + + if (hasInitializeFunction) + { + m_LuaScript->RunFunction(g_InitializeFunctionName); + } } else { diff --git a/Library/MeasureScript.h b/Library/MeasureScript.h index 0a6b9d7d..62aa1e43 100644 --- a/Library/MeasureScript.h +++ b/Library/MeasureScript.h @@ -29,7 +29,6 @@ public: virtual UINT GetTypeID() { return TypeID(); } - virtual void Initialize(); virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); virtual void Command(const std::wstring& command); @@ -42,7 +41,6 @@ protected: private: LuaScript* m_LuaScript; - bool m_HasInitializeFunction; bool m_HasUpdateFunction; bool m_HasGetStringFunction;