Skip to content

Commit 1fa37b3

Browse files
committed
Added Lua function utils.timer
1 parent 34e9dbb commit 1fa37b3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

scripting/lua_utils.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,23 @@ CFunctionListDlg dlg;
16541654

16551655
} // end of filterpicker
16561656

1657+
int timer (lua_State *L)
1658+
{
1659+
if (App.m_iCounterFrequency)
1660+
{
1661+
LARGE_INTEGER the_time;
1662+
QueryPerformanceCounter (&the_time);
1663+
lua_pushnumber (L, (double) the_time.QuadPart / (double) App.m_iCounterFrequency);
1664+
}
1665+
else
1666+
{
1667+
time_t timer;
1668+
time (&timer);
1669+
lua_pushnumber (L, (double) timer);
1670+
}
16571671

1672+
return 1; // 1 result
1673+
}
16581674

16591675
// table of operations
16601676
static const struct luaL_reg xmllib [] =
@@ -1683,6 +1699,7 @@ static const struct luaL_reg xmllib [] =
16831699
{"sendtofront", send_to_front},
16841700
{"shellexecute", shell_execute},
16851701
{"spellcheckdialog", spellcheckdialog},
1702+
{"timer", timer},
16861703
{"umsgbox", umsgbox}, // msgbox - UTF8
16871704
{"utf8decode", utf8decode},
16881705
{"utf8encode", utf8encode},

scripting/methods.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,6 +4177,7 @@ tInfoTypeMapping InfoTypes [] =
41774177
{ 118, "Variables have changed" },
41784178
{ 119, "Script engine active" },
41794179
{ 120, "Scroll bar visible" },
4180+
{ 121, "High-resolution timer available" },
41804181

41814182

41824183
// (numbers (longs) - calculated at runtime)
@@ -4536,6 +4537,7 @@ VARIANT CMUSHclientDoc::GetInfo(long InfoType)
45364537
case 118: SetUpVariantBool (vaResult, m_bVariablesChanged); break;
45374538
case 119: SetUpVariantBool (vaResult, m_ScriptEngine != NULL); break;
45384539
case 120: SetUpVariantBool (vaResult, m_bScrollBarWanted); break;
4540+
case 121: SetUpVariantBool (vaResult, App.m_iCounterFrequency != 0); break;
45394541

45404542

45414543
case 201: SetUpVariantLong (vaResult, m_total_lines); break;
@@ -4591,6 +4593,13 @@ VARIANT CMUSHclientDoc::GetInfo(long InfoType)
45914593
double ticks = (double) the_time.QuadPart / (double) App.m_iCounterFrequency;
45924594
SetUpVariantDouble (vaResult, ticks);
45934595
}
4596+
else
4597+
{
4598+
time_t timer;
4599+
time (&timer);
4600+
SetUpVariantDouble (vaResult, (double) timer);
4601+
}
4602+
45944603
break;
45954604

45964605
case 233: // time taken doing triggers

0 commit comments

Comments
 (0)