Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get exact type name for gcc #382

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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