Skip to content

Commit

Permalink
Testing something
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed Apr 4, 2024
1 parent 662604a commit 66b14c5
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion source/lua_ILuaInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <GarrysMod/Lua/Interface.h>
#include <GarrysMod/Lua/LuaObject.h>
#include "lua_threaded.h"
#include <sstream>

static int32_t metatype = GarrysMod::Lua::Type::NONE;
static const char metaname[] = "ILuaInterface";
Expand Down Expand Up @@ -149,14 +150,39 @@ LUA_FUNCTION_STATIC(newindex)
return 0;
}

std::string generateStackTrace(lua_State* L) {
std::stringstream trace;
int level = 0;
lua_Debug ar;

while (lua_getstack(L, level, &ar)) {
lua_getinfo(L, "Sl", &ar);

if (ar.source[0] == '@') {
trace << " " << level + 1 << ". " << ar.source << ":" << ar.currentline;
} else {
trace << " " << level + 1 << ". [" << ar.source << "]";
}
if (ar.name) {
trace << ": in function '" << ar.name << "'";
}
trace << std::endl;

level++;
}

return trace.str();
}

void HandleError(ILuaInterface* LUA, int result, const char* pFile)
{
if (result != 0)
{
std::string stack = generateStackTrace(LUA->GetState());
const char* err = func_lua_tostring(LUA->GetState(), -1, NULL);
LUA->Pop();

Msg("[ERROR] ILuaInterface:RunString: %s (%s)\n", err, pFile);
Msg("[ERROR] ILuaInterface:RunString: %s\n%s", err, stack.c_str());
return;
}
}
Expand Down

0 comments on commit 66b14c5

Please sign in to comment.