Merge branch 'master' of https://github.com/ChaiScript/ChaiScript
This commit is contained in:
commit
e3feb05e05
@ -8,6 +8,7 @@ option(BUILD_SAMPLES "Build Samples Folder" FALSE)
|
||||
|
||||
list(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
list(APPEND CPACK_SOURCE_IGNORE_FILES "\\\\.svn")
|
||||
list(APPEND CPACK_SOURCE_IGNORE_FILES "\\\\.git")
|
||||
list(APPEND CPACK_SOURCE_IGNORE_FILES ".swp")
|
||||
list(APPEND CPACK_SOURCE_IGNORE_FILES ".*~")
|
||||
|
||||
@ -61,7 +62,7 @@ IF(MSVC)
|
||||
ENDIF()
|
||||
ELSE()
|
||||
# -Wno-missing-field-initializers is for boost on macos
|
||||
ADD_DEFINITIONS(-Wall -Wextra -Wno-missing-field-initializers)
|
||||
ADD_DEFINITIONS(-Wall -Wextra -Wno-missing-field-initializers -Wshadow)
|
||||
ENDIF()
|
||||
|
||||
include_directories(include)
|
||||
@ -170,6 +171,10 @@ IF(BUILD_TESTING)
|
||||
target_link_libraries(type_info_test ${LIBS})
|
||||
add_test(NAME Type_Info_Test COMMAND type_info_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)
|
||||
|
||||
add_executable(multifile_test unittests/multifile_test_main.cpp unittests/multifile_test_chai.cpp
|
||||
unittests/multifile_test_module.cpp)
|
||||
target_link_libraries(multifile_test ${LIBS})
|
||||
|
@ -21,8 +21,8 @@ namespace chaiscript
|
||||
{
|
||||
public:
|
||||
bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to,
|
||||
const std::string &what)
|
||||
: from(t_from), to(&t_to), m_what(what)
|
||||
const std::string &t_what) throw()
|
||||
: from(t_from), to(&t_to), m_what(t_what)
|
||||
{
|
||||
}
|
||||
|
||||
@ -31,8 +31,8 @@ namespace chaiscript
|
||||
{
|
||||
}
|
||||
|
||||
bad_boxed_cast(const std::string &w) throw()
|
||||
: m_what(w)
|
||||
bad_boxed_cast(const std::string &t_what) throw()
|
||||
: m_what(t_what)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -581,6 +581,9 @@ namespace chaiscript
|
||||
|
||||
|
||||
m->add(user_type<std::runtime_error>(), "runtime_error");
|
||||
m->add(chaiscript::base_class<std::exception, std::runtime_error>());
|
||||
|
||||
|
||||
m->add(constructor<std::runtime_error (const std::string &)>(), "runtime_error");
|
||||
m->add(fun(boost::function<std::string (const std::runtime_error &)>(&what)), "what");
|
||||
|
||||
|
@ -203,14 +203,14 @@ namespace chaiscript
|
||||
throw exception::bad_boxed_cast(">> only valid for integer types");
|
||||
}
|
||||
|
||||
Boxed_Value smart_size(boost::int64_t i) const
|
||||
Boxed_Value smart_size(boost::int64_t t_i) const
|
||||
{
|
||||
if (i < boost::integer_traits<int>::const_min
|
||||
|| i > boost::integer_traits<int>::const_max)
|
||||
if (t_i < boost::integer_traits<int>::const_min
|
||||
|| t_i > boost::integer_traits<int>::const_max)
|
||||
{
|
||||
return Boxed_Value(i);
|
||||
return Boxed_Value(t_i);
|
||||
} else {
|
||||
return Boxed_Value(static_cast<int>(i));
|
||||
return Boxed_Value(static_cast<int>(t_i));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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() {}
|
||||
};
|
||||
}
|
||||
|
||||
@ -74,17 +76,17 @@ namespace chaiscript
|
||||
{
|
||||
}
|
||||
|
||||
virtual Boxed_Value convert(const Boxed_Value &derived)
|
||||
virtual Boxed_Value convert(const Boxed_Value &t_derived)
|
||||
{
|
||||
if (derived.get_type_info().bare_equal(user_type<Derived>()))
|
||||
if (t_derived.get_type_info().bare_equal(user_type<Derived>()))
|
||||
{
|
||||
if (derived.is_pointer())
|
||||
if (t_derived.is_pointer())
|
||||
{
|
||||
// Dynamic cast out the contained boxed value, which we know is the type we want
|
||||
if (derived.is_const())
|
||||
if (t_derived.is_const())
|
||||
{
|
||||
boost::shared_ptr<const Base> data
|
||||
= boost::dynamic_pointer_cast<const Base>(detail::Cast_Helper<boost::shared_ptr<const Derived> >::cast(derived));
|
||||
= boost::dynamic_pointer_cast<const Base>(detail::Cast_Helper<boost::shared_ptr<const Derived> >::cast(t_derived));
|
||||
if (!data)
|
||||
{
|
||||
throw std::bad_cast();
|
||||
@ -93,7 +95,7 @@ namespace chaiscript
|
||||
return Boxed_Value(data);
|
||||
} else {
|
||||
boost::shared_ptr<Base> data
|
||||
= boost::dynamic_pointer_cast<Base>(detail::Cast_Helper<boost::shared_ptr<Derived> >::cast(derived));
|
||||
= boost::dynamic_pointer_cast<Base>(detail::Cast_Helper<boost::shared_ptr<Derived> >::cast(t_derived));
|
||||
|
||||
if (!data)
|
||||
{
|
||||
@ -104,19 +106,19 @@ namespace chaiscript
|
||||
}
|
||||
} else {
|
||||
// Pull the reference out of the contained boxed value, which we know is the type we want
|
||||
if (derived.is_const())
|
||||
if (t_derived.is_const())
|
||||
{
|
||||
const Derived &d = detail::Cast_Helper<const Derived &>::cast(derived);
|
||||
const Derived &d = detail::Cast_Helper<const Derived &>::cast(t_derived);
|
||||
const Base &data = dynamic_cast<const Base &>(d);
|
||||
return Boxed_Value(boost::cref(data));
|
||||
} else {
|
||||
Derived &d = detail::Cast_Helper<Derived &>::cast(derived);
|
||||
Derived &d = detail::Cast_Helper<Derived &>::cast(t_derived);
|
||||
Base &data = dynamic_cast<Base &>(d);
|
||||
return Boxed_Value(boost::ref(data));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "Unknown dynamic_cast_conversion");
|
||||
throw exception::bad_boxed_dynamic_cast(t_derived.get_type_info(), typeid(Base), "Unknown dynamic_cast_conversion");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -69,7 +69,7 @@ namespace chaiscript
|
||||
{
|
||||
call_func(fun, params);
|
||||
return Handle_Return<void>::handle();
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -633,13 +633,13 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
try {
|
||||
const std::string & function_name = this->children[0]->text;
|
||||
const std::string & annotation = this->annotation?this->annotation->text:"";
|
||||
const std::string & l_function_name = this->children[0]->text;
|
||||
const std::string & l_annotation = this->annotation?this->annotation->text:"";
|
||||
t_ss.add(Proxy_Function
|
||||
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>,
|
||||
boost::ref(t_ss), this->children.back(),
|
||||
t_param_names, _1), static_cast<int>(numparams), this->children.back(),
|
||||
annotation, guard)), function_name);
|
||||
l_annotation, guard)), l_function_name);
|
||||
}
|
||||
catch (reserved_word_error &e) {
|
||||
throw Eval_Error("Reserved word used as function name '" + e.word + "'");
|
||||
@ -1069,8 +1069,8 @@ namespace chaiscript
|
||||
try {
|
||||
this->children.back()->children[0]->eval(t_ss);
|
||||
}
|
||||
catch (Eval_Error &ee) {
|
||||
ee.call_stack.push_back(this->children.back()->children[0]);
|
||||
catch (Eval_Error &ee2) {
|
||||
ee2.call_stack.push_back(this->children.back()->children[0]);
|
||||
t_ss.pop_scope();
|
||||
throw;
|
||||
}
|
||||
@ -1334,7 +1334,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
try {
|
||||
const std::string & annotation = this->annotation?this->annotation->text:"";
|
||||
const std::string & l_annotation = this->annotation?this->annotation->text:"";
|
||||
const std::string & class_name = this->children[0]->text;
|
||||
const std::string & function_name = this->children[1]->text;
|
||||
if (function_name == class_name) {
|
||||
@ -1343,7 +1343,7 @@ namespace chaiscript
|
||||
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>,
|
||||
boost::ref(t_ss), this->children.back(),
|
||||
t_param_names, _1), static_cast<int>(numparams), this->children.back(),
|
||||
annotation, guard)))), function_name);
|
||||
l_annotation, guard)))), function_name);
|
||||
|
||||
}
|
||||
else {
|
||||
@ -1358,7 +1358,7 @@ namespace chaiscript
|
||||
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Dispatch_Engine>,
|
||||
boost::ref(t_ss), this->children.back(),
|
||||
t_param_names, _1), static_cast<int>(numparams), this->children.back(),
|
||||
annotation, guard)), ti)), function_name);
|
||||
l_annotation, guard)), ti)), function_name);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
21
unittests/eval_catch_exception_test.cpp
Normal file
21
unittests/eval_catch_exception_test.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
// Tests to make sure that the order in which function dispatches occur is correct
|
||||
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
chaiscript::ChaiScript chai;
|
||||
|
||||
try {
|
||||
chai.eval("throw(runtime_error(\"error\"));");
|
||||
} catch (const chaiscript::Boxed_Value &bv) {
|
||||
const std::exception &e = chaiscript::boxed_cast<const std::exception &>(bv);
|
||||
if (e.what() == std::string("error"))
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
load_module("test_module")
|
||||
|
||||
var t0 = TestBaseType();
|
||||
var t0 = TestBaseType()
|
||||
var t = TestDerivedType();
|
||||
|
||||
assert_equal(t0.func(), 0);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user