Script: Fixed that Initialize() was not called when the script is changed dynamically

This commit is contained in:
Birunthan Mohanathas 2012-07-18 17:41:28 +03:00
parent 67a57ca9ee
commit a0a0c61e79
2 changed files with 6 additions and 19 deletions

View File

@ -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
{

View File

@ -29,7 +29,6 @@ public:
virtual UINT GetTypeID() { return TypeID<CMeasureScript>(); }
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;