Fix problem with method specifiers for bad_dynamic_boxed_cast exception. Add support for operators to Utility.hpp

This commit is contained in:
Jason Turner
2011-03-11 17:54:55 -07:00
parent d9a92a5148
commit 46a669dab1
6 changed files with 21 additions and 11 deletions

View File

@@ -21,7 +21,7 @@ namespace chaiscript
{
public:
bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to,
const std::string &what)
const std::string &what) throw()
: from(t_from), to(&t_to), m_what(what)
{
}

View File

@@ -21,7 +21,7 @@ namespace chaiscript
{
public:
bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to,
const std::string &t_what)
const std::string &t_what) throw()
: bad_boxed_cast(t_from, t_to, t_what)
{
}
@@ -35,6 +35,8 @@ namespace chaiscript
: bad_boxed_cast(w)
{
}
virtual ~bad_boxed_dynamic_cast() throw() {}
};
}

View File

@@ -53,10 +53,10 @@ namespace chaiscript
{
inline std::string class_name_translator(const std::string &t_name)
{
size_t colon = t_name.find_last_of("::");
size_t colon = t_name.rfind("::");
if (colon != std::string::npos)
{
return t_name.substr(colon+1, std::string::npos);
return t_name.substr(colon+2, std::string::npos);
} else {
return t_name;
}
@@ -64,13 +64,16 @@ namespace chaiscript
inline std::string method_name_translator(const std::string &t_name)
{
size_t colon = t_name.find_last_of("::");
if (colon != std::string::npos)
size_t namestart = t_name.rfind("operator");
namestart = (namestart == std::string::npos)?0:namestart+strlen("operator");
if (namestart == 0)
{
return t_name.substr(colon+1, std::string::npos);
} else {
return t_name;
}
namestart = t_name.rfind("::");
namestart = (namestart == std::string::npos)?0:namestart+strlen("::");
}
return t_name.substr(namestart, std::string::npos);
}
}
}

View File

@@ -5,6 +5,8 @@
class TestBaseType
{
public:
TestBaseType() {}
TestBaseType(int) {}
virtual ~TestBaseType() {}
virtual int func() { return 0; }
@@ -40,6 +42,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
m->add(chaiscript::user_type<TestDerivedType>(), "TestDerivedType");
m->add(chaiscript::constructor<TestBaseType ()>(), "TestBaseType");
// m->add(chaiscript::constructor<TestBaseType (int)>(), "TestBaseType");
m->add(chaiscript::constructor<TestBaseType (const TestBaseType &)>(), "TestBaseType");
m->add(chaiscript::constructor<TestDerivedType ()>(), "TestDerivedType");

View File

@@ -1,6 +1,6 @@
load_module("test_module")
var t0 = TestBaseType();
var t0 = TestBaseType()
var t = TestDerivedType();
assert_equal(t0.func(), 0);

View File

@@ -24,6 +24,7 @@ int main()
((function3))
((functionOverload)(std::string (Test::*)(double)))
((functionOverload)(std::string (Test::*)(int)))
((operator=))
);
chaiscript::ChaiScript chai;
@@ -32,6 +33,7 @@ int main()
&& chai.eval<std::string>("var t = Test(); t.functionOverload(1); ") == "int"
&& chai.eval<std::string>("var t = Test(); t.functionOverload(1.1); ") == "double")
{
chai.eval("t = Test();");
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;