Skip to content

Commit 7460cc8

Browse files
committed
Add 'debugSleep' Lua function
This function makes implementing a debugger possible (more on that later)
1 parent a805943 commit 7460cc8

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ void CLuaUtilDefs::LoadFunctions ( void )
3838
CLuaCFunctions::AddFunction ( "pregFind", PregFind );
3939
CLuaCFunctions::AddFunction ( "pregReplace", PregReplace );
4040
CLuaCFunctions::AddFunction ( "pregMatch", PregMatch );
41+
42+
// Debug functions
43+
CLuaCFunctions::AddFunction("debugSleep", DebugSleep);
4144
}
4245

4346
int CLuaUtilDefs::DisabledFunction ( lua_State* luaVM )
@@ -559,3 +562,44 @@ int CLuaUtilDefs::PregMatch ( lua_State* luaVM )
559562
lua_pushboolean ( luaVM, false );
560563
return 1;
561564
}
565+
566+
int CLuaUtilDefs::DebugSleep(lua_State* luaVM)
567+
{
568+
std::size_t milliseconds;
569+
570+
CScriptArgReader argStream(luaVM);
571+
argStream.ReadNumber(milliseconds);
572+
573+
if (!argStream.HasErrors())
574+
{
575+
#ifdef MTA_CLIENT
576+
if (!g_pClientGame->GetDevelopmentMode())
577+
#else
578+
if (!g_pGame->GetDevelopmentMode())
579+
#endif
580+
{
581+
m_pScriptDebugging->LogError(luaVM, "This function can only be used in development mode");
582+
lua_pushboolean(luaVM, false);
583+
return 1;
584+
}
585+
586+
587+
// Process HTTP
588+
#ifdef MTA_CLIENT
589+
g_pNet->GetHTTPDownloadManager(EDownloadMode::CALL_REMOTE_RESTRICTED)->ProcessQueuedFiles();
590+
#else
591+
g_pNetServer->GetHTTPDownloadManager(EDownloadMode::CALL_REMOTE)->ProcessQueuedFiles();
592+
#endif
593+
594+
// Sleep a bit
595+
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
596+
597+
lua_pushboolean(luaVM, true);
598+
return 1;
599+
}
600+
else
601+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
602+
603+
lua_pushboolean(luaVM, false);
604+
return 1;
605+
}

Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ class CLuaUtilDefs : public CLuaDefs
4545
LUA_DECLARE ( PregFind );
4646
LUA_DECLARE ( PregReplace );
4747
LUA_DECLARE ( PregMatch );
48+
49+
// Debug functions
50+
LUA_DECLARE(DebugSleep);
4851
};

0 commit comments

Comments
 (0)