Reduce exceptions on startup to minimum

This still has some exceptions thrown during the loading of modules
since I have no way of knowing where the operating system
`dlopen` and `LoadLibrary` functions will search for me to pre-check
it.

Closes #158
This commit is contained in:
Jason Turner
2015-04-06 13:17:41 -06:00
parent f953f9b297
commit 962bdf4b3c
6 changed files with 39 additions and 36 deletions

View File

@@ -199,6 +199,14 @@ namespace chaiscript
{
}
bool has_function(const Proxy_Function &new_f, const std::string &name)
{
return std::any_of(m_funcs.begin(), m_funcs.end(), [&](const std::pair<Proxy_Function, std::string> &existing_f) {
return existing_f.second == name && *(existing_f.first) == *(new_f);
});
}
private:
std::vector<std::pair<Type_Info, std::string> > m_typeinfos;
std::vector<std::pair<Proxy_Function, std::string> > m_funcs;
@@ -580,7 +588,7 @@ namespace chaiscript
}
/// Returns the type info for a named type
Type_Info get_type(const std::string &name) const
Type_Info get_type(const std::string &name, bool t_throw = true) const
{
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
@@ -591,7 +599,11 @@ namespace chaiscript
return itr->second;
}
throw std::range_error("Type Not Known");
if (t_throw) {
throw std::range_error("Type Not Known");
} else {
return Type_Info();
}
}
/// Returns the registered name of a known type_info object