Skip to content

Commit

Permalink
Improve GetStackAsString output and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Foereaper authored Nov 10, 2024
1 parent b59c832 commit 58b9753
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 16 deletions.
21 changes: 17 additions & 4 deletions methods/CMangos/GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -2522,14 +2522,27 @@ namespace LuaGlobalFunctions

static std::string GetStackAsString(Eluna* E)
{
std::ostringstream oss;
std::string output;
int top = lua_gettop(E->L);
for (int i = 1; i <= top; ++i)
{
oss << luaL_tolstring(E->L, i, NULL);
lua_pop(E->L, 1);
if (lua_isstring(E->L, i))
{
output += lua_tostring(E->L, i);
}
else
{
lua_getglobal(E->L, "tostring");
lua_pushvalue(E->L, i);
lua_call(E->L, 1, 1);
output += lua_tostring(E->L, -1);
lua_pop(E->L, 1);
}

if (i < top)
output += "\t";
}
return oss.str();
return output;
}

/**
Expand Down
21 changes: 17 additions & 4 deletions methods/Mangos/GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -2279,14 +2279,27 @@ namespace LuaGlobalFunctions

static std::string GetStackAsString(Eluna* E)
{
std::ostringstream oss;
std::string output;
int top = lua_gettop(E->L);
for (int i = 1; i <= top; ++i)
{
oss << luaL_tolstring(E->L, i, NULL);
lua_pop(E->L, 1);
if (lua_isstring(E->L, i))
{
output += lua_tostring(E->L, i);
}
else
{
lua_getglobal(E->L, "tostring");
lua_pushvalue(E->L, i);
lua_call(E->L, 1, 1);
output += lua_tostring(E->L, -1);
lua_pop(E->L, 1);
}

if (i < top)
output += "\t";
}
return oss.str();
return output;
}

/**
Expand Down
21 changes: 17 additions & 4 deletions methods/TrinityCore/GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -2404,14 +2404,27 @@ namespace LuaGlobalFunctions

static std::string GetStackAsString(Eluna* E)
{
std::ostringstream oss;
std::string output;
int top = lua_gettop(E->L);
for (int i = 1; i <= top; ++i)
{
oss << luaL_tolstring(E->L, i, NULL);
lua_pop(E->L, 1);
if (lua_isstring(E->L, i))
{
output += lua_tostring(E->L, i);
}
else
{
lua_getglobal(E->L, "tostring");
lua_pushvalue(E->L, i);
lua_call(E->L, 1, 1);
output += lua_tostring(E->L, -1);
lua_pop(E->L, 1);
}

if (i < top)
output += "\t";
}
return oss.str();
return output;
}

/**
Expand Down
21 changes: 17 additions & 4 deletions methods/VMangos/GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -2222,14 +2222,27 @@ namespace LuaGlobalFunctions

static std::string GetStackAsString(Eluna* E)
{
std::ostringstream oss;
std::string output;
int top = lua_gettop(E->L);
for (int i = 1; i <= top; ++i)
{
oss << luaL_tolstring(E->L, i, NULL);
lua_pop(E->L, 1);
if (lua_isstring(E->L, i))
{
output += lua_tostring(E->L, i);
}
else
{
lua_getglobal(E->L, "tostring");
lua_pushvalue(E->L, i);
lua_call(E->L, 1, 1);
output += lua_tostring(E->L, -1);
lua_pop(E->L, 1);
}

if (i < top)
output += "\t";
}
return oss.str();
return output;
}

/**
Expand Down

0 comments on commit 58b9753

Please sign in to comment.