From 6e7201f52aca7f198980bfbd95872e384f3326d6 Mon Sep 17 00:00:00 2001 From: fxliang Date: Fri, 3 Jan 2025 17:40:52 +0800 Subject: [PATCH] get exact type name for gcc --- src/lib/lua_templates.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib/lua_templates.h b/src/lib/lua_templates.h index 13076db..57acde4 100644 --- a/src/lib/lua_templates.h +++ b/src/lib/lua_templates.h @@ -2,6 +2,9 @@ #define LIB_LUA_TEMPLATES_H_ #include "lua.h" +#ifdef __GNUC__ +#include +#endif #include #include #include @@ -56,6 +59,9 @@ class LUAWRAPPER_LOCAL C_State { struct LUAWRAPPER_LOCAL LuaTypeInfo { const std::type_info *ti; size_t hash; +#ifdef __GNUC__ + mutable std::unique_ptr demangleName_; +#endif template static const LuaTypeInfo &make() { @@ -65,7 +71,17 @@ struct LUAWRAPPER_LOCAL LuaTypeInfo { } const char *name() const { +#ifdef __GNUC__ + int status = 0; + std::unique_ptr demangledName( + abi::__cxa_demangle(ti->name(), nullptr, nullptr, &status)); + if (status) + return ti->name(); + demangleName_ = std::move(demangledName); + return demangleName_.get(); +#else return ti->name(); +#endif } bool operator==(const LuaTypeInfo &o) const {