Add the ability to look up user defined typenames

Closes #124
This commit is contained in:
Jason Turner 2014-08-17 09:05:29 -06:00
parent 3a775097dd
commit cb1c7730cf
3 changed files with 38 additions and 0 deletions

View File

@ -275,6 +275,10 @@ if(BUILD_TESTING)
target_link_libraries(type_info_test ${LIBS})
add_test(NAME Type_Info_Test COMMAND type_info_test)
add_executable(type_name_test unittests/type_name_test.cpp)
target_link_libraries(type_name_test ${LIBS})
add_test(NAME Type_Name_Test COMMAND type_name_test)
add_executable(eval_catch_exception_test unittests/eval_catch_exception_test.cpp)
target_link_libraries(eval_catch_exception_test ${LIBS})
add_test(NAME Eval_Catch_Exception_Test COMMAND eval_catch_exception_test)

View File

@ -503,6 +503,18 @@ namespace chaiscript
return ss.str();
}
std::string get_type_name(const Type_Info &ti) const
{
return m_engine.get_type_name(ti);
}
template<typename T>
std::string get_type_name() const
{
return get_type_name(user_type<T>());
}
/// \brief Loads and parses a file. If the file is already, it is not reloaded
/// The use paths specified at ChaiScript construction time are searched for the
/// requested file.

View File

@ -0,0 +1,22 @@
// Tests to make sure that the order in which function dispatches occur is correct
#include <chaiscript/chaiscript.hpp>
#include <cstdlib>
class MyClass
{
};
int main()
{
chaiscript::ChaiScript chai;
auto type = chaiscript::user_type<MyClass>();
chai.add(type, "MyClass");
if (chai.get_type_name(type) == "MyClass" && chai.get_type_name<MyClass>() == "MyClass")
{
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
}
}