Skip to content

Commit

Permalink
get exact type name for gcc
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang committed Jan 3, 2025
1 parent e3912a4 commit 6e7201f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib/lua_templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define LIB_LUA_TEMPLATES_H_

#include "lua.h"
#ifdef __GNUC__
#include <cxxabi.h>
#endif
#include <typeinfo>
#include <vector>
#include <set>
Expand Down Expand Up @@ -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<char[]> demangleName_;
#endif

template<typename T>
static const LuaTypeInfo &make() {
Expand All @@ -65,7 +71,17 @@ struct LUAWRAPPER_LOCAL LuaTypeInfo {
}

const char *name() const {
#ifdef __GNUC__
int status = 0;
std::unique_ptr<char[]> 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 {
Expand Down

0 comments on commit 6e7201f

Please sign in to comment.