Throw internal error instead of crashing if trying to use nonexistent class

This commit is contained in:
Ilari Liusvaara 2013-12-19 23:34:02 +02:00
parent 007ef21d7a
commit 9df05e03a9

View file

@ -687,6 +687,8 @@ template<class T> class lua_class;
*/
template<class T> lua_class<T>& objclass()
{
if(lua_class_types().count(typeid(T)))
throw std::runtime_error("Internal error: Lua class not found!");
return *reinterpret_cast<lua_class<T>*>(lua_class_types()[typeid(T)]);
}
@ -856,14 +858,23 @@ public:
*/
static bool is(lua_state& state, int arg) throw()
{
return objclass<T>()._is(state, arg);
try {
return objclass<T>()._is(state, arg);
} catch(...) {
return false;
}
}
/**
* Get name of class.
*/
static const std::string& get_name()
{
return objclass<T>().name;
try {
return objclass<T>().name;
} catch(...) {
static std::string foo = "???";
return foo;
}
}
/**
* Format instance of this class as string.