diff --git a/sol/demangle.hpp b/sol/demangle.hpp index 3d1d11ba..d2ef43b7 100644 --- a/sol/demangle.hpp +++ b/sol/demangle.hpp @@ -24,57 +24,40 @@ #include -#ifdef _MSC_VER -/*#include -#include -*/ -namespace sol { -namespace detail { - - - std::string demangle(const std::type_info& id) { - /*std::string realname(2048, '\0'); - DWORD result = UnDecorateSymbolName(id.raw_name(), &realname[0], - static_cast(realname.size()), UNDNAME_NAME_ONLY | UNDNAME_32_BIT_DECODE); - if (result == 0) - return ""; - realname.resize(result); - */ - const static std::string removals[ 2 ] = { - "struct ", - "class " - }; - std::string realname = id.name(); - for (std::size_t r = 0; r < 2; ++r) { - auto found = realname.find(removals[ r ]); - if (found == std::string::npos) - continue; - realname.erase(found, removals[r].size()); - } - return realname; - } - -#elif __GNUC__ || __clang__ +#if defined(__GNUC__) || defined(__clang__) #include +#endif namespace sol { namespace detail { +#ifdef _MSC_VER +std::string demangle(const std::type_info& id) { + const static std::string removals[2] = { "struct ", "class " }; + std::string realname = id.name(); + for(std::size_t r = 0; r < 2; ++r) { + auto found = realname.find(removals[r]); - std::string demangle(const std::type_info& id) { - int status; - char* unmangled = abi::__cxa_demangle(id.name(), 0, 0, &status); - std::string realname = unmangled; - free(unmangled); - return realname; + if(found == std::string::npos) { + continue; + } + + realname.erase(found, removals[r].size()); } + return realname; +} + +#elif defined(__GNUC__) || defined(__clang__) +std::string demangle(const std::type_info& id) { + int status; + char* unmangled = abi::__cxa_demangle(id.name(), 0, 0, &status); + std::string realname = unmangled; + free(unmangled); + return realname; +} #else -namespace sol { -namespace detail { - -#error Implement demangling for this platform -#endif // VC++ || GCC || Others - +#error Compiler not supported for demangling +#endif // compilers } // detail } // sol