Skip to content

Commit 175d86e

Browse files
committed
feat(Lua): Added stack dump to error message
1 parent 1d65a8f commit 175d86e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

UE4SS/src/LuaType/LuaUObject.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,41 @@ namespace RC::LuaType
10891089
params.lua.throw_error(fmt::format("[push_textproperty] Unknown Operation ({}) not supported", static_cast<int32_t>(params.operation)));
10901090
}
10911091

1092+
static auto get_stack_dump(const LuaMadeSimple::Lua& lua, const char* message = "") -> std::string
1093+
{
1094+
auto lua_state = lua.get_lua_state();
1095+
auto out_message = fmt::format("\n\nLUA Stack dump -> START------------------------------\n{}\n", message);
1096+
int top = lua_gettop(lua_state);
1097+
for (int i = 1; i <= top; i++)
1098+
{
1099+
out_message.append(fmt::format("{}\t{}\t", i, luaL_typename(lua_state, i)));
1100+
switch (lua_type(lua_state, i))
1101+
{
1102+
case LUA_TNUMBER:
1103+
out_message.append(fmt::format("{}", lua_tonumber(lua_state, i)));
1104+
break;
1105+
case LUA_TSTRING:
1106+
out_message.append(fmt::format("{}", lua_tostring(lua_state, i)));
1107+
break;
1108+
case LUA_TBOOLEAN:
1109+
out_message.append(fmt::format("{}", (lua_toboolean(lua_state, i) ? "true" : "false")));
1110+
break;
1111+
case LUA_TNIL:
1112+
out_message.append("nil");
1113+
break;
1114+
case LUA_TFUNCTION:
1115+
out_message.append("function");
1116+
break;
1117+
default:
1118+
out_message.append(fmt::format("{}", lua_topointer(lua_state, i)));
1119+
break;
1120+
}
1121+
out_message.append("\n");
1122+
}
1123+
out_message.append("\nLUA Stack dump -> END----------------------------\n\n");
1124+
return out_message;
1125+
}
1126+
10921127
auto push_strproperty(const PusherParams& params) -> void
10931128
{
10941129
Unreal::FString* string = static_cast<Unreal::FString*>(params.data);
@@ -1118,6 +1153,7 @@ namespace RC::LuaType
11181153
else
11191154
{
11201155
auto error = to_string(fmt::format(STR("[push_strproperty] StrProperty ({}) can only be set to a string or FString"), params.property ? params.property->GetFullName() : STR("N/A")));
1156+
error.append(get_stack_dump(params.lua));
11211157
params.lua.throw_error(error);
11221158
}
11231159
return;

0 commit comments

Comments
 (0)