2011-07-05 13:41:05 +00:00
|
|
|
#include "../../StdAfx.h"
|
|
|
|
#include "../LuaManager.h"
|
|
|
|
#include "../../Measure.h"
|
2011-07-27 10:42:35 +00:00
|
|
|
#include "../../MeterWindow.h"
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
static int Measure_GetName(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeasure* self = (CMeasure*)tolua_tousertype(L, 1, 0);
|
|
|
|
const WCHAR* val = (const WCHAR*)self->GetName();
|
2011-09-03 16:45:29 +00:00
|
|
|
LuaManager::PushWide(L, val);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-07-27 10:42:35 +00:00
|
|
|
static int Measure_GetOption(lua_State* L)
|
2011-07-05 13:41:05 +00:00
|
|
|
{
|
|
|
|
CMeasure* self = (CMeasure*)tolua_tousertype(L, 1, 0);
|
2011-07-27 10:42:35 +00:00
|
|
|
CMeterWindow* meterWindow = self->GetMeterWindow();
|
|
|
|
CConfigParser& parser = meterWindow->GetParser();
|
2011-07-05 13:41:05 +00:00
|
|
|
|
2011-09-03 16:45:29 +00:00
|
|
|
std::wstring strTmp = LuaManager::ToWide(L, 2);
|
2011-07-27 10:42:35 +00:00
|
|
|
strTmp = parser.GetValue(self->GetName(), strTmp, L"");
|
|
|
|
|
|
|
|
parser.SetBuiltInVariable(L"CURRENTSECTION", self->GetName()); // Set temporarily
|
|
|
|
parser.ReplaceVariables(strTmp);
|
|
|
|
parser.SetBuiltInVariable(L"CURRENTSECTION", L""); // Reset
|
2011-07-29 17:18:21 +00:00
|
|
|
parser.ReplaceMeasures(strTmp);
|
2011-07-27 10:42:35 +00:00
|
|
|
|
2011-09-03 16:45:29 +00:00
|
|
|
LuaManager::PushWide(L, strTmp.c_str());
|
2011-07-05 13:41:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Measure_Disable(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeasure* self = (CMeasure*)tolua_tousertype(L, 1, 0);
|
|
|
|
self->Disable();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Measure_Enable(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeasure* self = (CMeasure*)tolua_tousertype(L, 1, 0);
|
|
|
|
self->Enable();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Measure_GetValue(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeasure* self = (CMeasure*)tolua_tousertype(L, 1, 0);
|
|
|
|
double val = (double)self->GetValue();
|
2011-07-27 10:42:35 +00:00
|
|
|
lua_pushnumber(L, (lua_Number)val);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Measure_GetRelativeValue(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeasure* self = (CMeasure*)tolua_tousertype(L, 1, 0);
|
|
|
|
double val = (double)self->GetRelativeValue();
|
2011-07-27 10:42:35 +00:00
|
|
|
lua_pushnumber(L, (lua_Number)val);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Measure_GetValueRange(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeasure* self = (CMeasure*)tolua_tousertype(L, 1, 0);
|
|
|
|
double val = (double)self->GetValueRange();
|
2011-07-27 10:42:35 +00:00
|
|
|
lua_pushnumber(L, (lua_Number)val);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Measure_GetMinValue(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeasure* self = (CMeasure*)tolua_tousertype(L, 1, 0);
|
|
|
|
double val = (double)self->GetMinValue();
|
2011-07-27 10:42:35 +00:00
|
|
|
lua_pushnumber(L, (lua_Number)val);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Measure_GetMaxValue(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeasure* self = (CMeasure*)tolua_tousertype(L, 1, 0);
|
|
|
|
double val = (double)self->GetMaxValue();
|
2011-07-27 10:42:35 +00:00
|
|
|
lua_pushnumber(L, (lua_Number)val);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Measure_GetStringValue(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeasure* self = (CMeasure*)tolua_tousertype(L, 1, 0);
|
|
|
|
AUTOSCALE autoScale = ((AUTOSCALE)(int)tolua_tonumber(L, 2, AUTOSCALE_OFF));
|
|
|
|
double scale = (double)tolua_tonumber(L, 3, 1.0);
|
|
|
|
int decimals = (int)tolua_tonumber(L, 4, 0);
|
|
|
|
bool percentual = (bool)tolua_toboolean(L, 5, false);
|
|
|
|
|
|
|
|
const WCHAR* val = self->GetStringValue(autoScale, scale, decimals, percentual);
|
2011-09-03 16:45:29 +00:00
|
|
|
LuaManager::PushWide(L, val);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LuaManager::RegisterMeasure(lua_State* L)
|
|
|
|
{
|
|
|
|
tolua_usertype(L, "CMeasure");
|
2011-07-29 17:18:21 +00:00
|
|
|
tolua_cclass(L, "CMeasure", "CMeasure", "", NULL);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
tolua_beginmodule(L, "CMeasure");
|
|
|
|
tolua_function(L, "GetName", Measure_GetName);
|
2011-07-27 10:42:35 +00:00
|
|
|
tolua_function(L, "GetOption", Measure_GetOption);
|
2011-07-05 13:41:05 +00:00
|
|
|
tolua_function(L, "Disable", Measure_Disable);
|
|
|
|
tolua_function(L, "Enable", Measure_Enable);
|
|
|
|
tolua_function(L, "GetValue", Measure_GetValue);
|
|
|
|
tolua_function(L, "GetRelativeValue", Measure_GetRelativeValue);
|
|
|
|
tolua_function(L, "GetValueRange", Measure_GetValueRange);
|
|
|
|
tolua_function(L, "GetMinValue", Measure_GetMinValue);
|
|
|
|
tolua_function(L, "GetMaxValue", Measure_GetMaxValue);
|
|
|
|
tolua_function(L, "GetStringValue", Measure_GetStringValue);
|
|
|
|
tolua_endmodule(L);
|
|
|
|
}
|