From 13f98fa8ce20d09fa8b83b3ae7d2666400252814 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 30 Jan 2012 11:26:46 -0700 Subject: [PATCH 1/5] Move "use" function to be public --- .../chaiscript/language/chaiscript_engine.hpp | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 86246db..5a6102a 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -285,33 +285,6 @@ namespace chaiscript return do_eval(t_e, "__EVAL__", true); } - void use(const std::string &t_filename) - { - for (size_t i = 0; i < m_usepaths.size(); ++i) - { - - try { - const std::string appendedpath = m_usepaths[i] + t_filename; - - chaiscript::detail::threading::lock_guard l(m_use_mutex); - chaiscript::detail::threading::shared_lock l2(m_mutex); - - if (m_used_files.count(appendedpath) == 0) - { - m_used_files.insert(appendedpath); - l2.unlock(); - eval_file(appendedpath); - } - } catch (const exception::file_not_found_error &) { - if (i == m_usepaths.size() - 1) - { - throw exception::file_not_found_error(t_filename); - } - - // failed to load, try the next path - } - } - } /** * Returns the current evaluation m_engine @@ -417,6 +390,40 @@ namespace chaiscript build_eval_system(); } + /// \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. + /// + /// \param[in] t_filename Filename to load and evaluate + void use(const std::string &t_filename) + { + for (size_t i = 0; i < m_usepaths.size(); ++i) + { + try { + const std::string appendedpath = m_usepaths[i] + t_filename; + + chaiscript::detail::threading::lock_guard l(m_use_mutex); + chaiscript::detail::threading::shared_lock l2(m_mutex); + + if (m_used_files.count(appendedpath) == 0) + { + m_used_files.insert(appendedpath); + l2.unlock(); + eval_file(appendedpath); + } + + return; // return, we loaded it, or it was already loaded + } catch (const exception::file_not_found_error &) { + if (i == m_usepaths.size() - 1) + { + throw exception::file_not_found_error(t_filename); + } + + // failed to load, try the next path + } + } + } + /// \brief Adds a constant object that is available in all contexts and to all threads /// \param[in] t_bv Boxed_Value to add as a global /// \param[in] t_name Name of the value to add From 3b959319734495c66025e5a99edb9bddd71cc6c4 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 30 Jan 2012 11:53:12 -0700 Subject: [PATCH 2/5] Fixup some documentation --- include/chaiscript/chaiscript.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 0f17284..38b2cea 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -192,8 +192,8 @@ /// Overloaded methods will need some help, to hint the compiler as to which overload you want: /// /// \code -/// chai.add(fun(&MyClass::overloadedmethod), "overloadedmethod")); -/// chai.add(fun(&MyClass::overloadedmethod, "overloadedmethod")); +/// chai.add(fun(&MyClass::overloadedmethod), "overloadedmethod"); +/// chai.add(fun(&MyClass::overloadedmethod), "overloadedmethod"); /// \endcode /// /// There are also shortcuts built into chaiscript::fun for binding up to the first two parameters of the function. From 41b0c7768c74d73f6510f5f92df875b27b71abae Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 11 Mar 2012 14:06:18 -0600 Subject: [PATCH 3/5] Adding header files to CMakeLists.txt. Hopefully this will help them show up in IDEs (works for Qt Creator so far). --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6ffca2..f3590fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,10 @@ include_directories(include) set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0" "1.43" "1.43.0" "1.42" "1.42.0" "1.41") set(Boost_USE_MULTITHREADED ON) +set (Chai_INCLUDES include/chaiscript/chaiscript.hpp include/chaiscript/chaiscript_threading.hpp include/chaiscript/dispatchkit/bad_boxed_cast.hpp include/chaiscript/dispatchkit/bind_first.hpp include/chaiscript/dispatchkit/bootstrap.hpp include/chaiscript/dispatchkit/bootstrap_stl.hpp include/chaiscript/dispatchkit/boxed_cast.hpp include/chaiscript/dispatchkit/boxed_cast_helper.hpp include/chaiscript/dispatchkit/boxed_number.hpp include/chaiscript/dispatchkit/boxed_value.hpp include/chaiscript/dispatchkit/dispatchkit.hpp include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp include/chaiscript/dispatchkit/dynamic_object.hpp include/chaiscript/dispatchkit/exception_specification.hpp include/chaiscript/dispatchkit/function_call.hpp include/chaiscript/dispatchkit/function_call_detail.hpp include/chaiscript/dispatchkit/handle_return.hpp include/chaiscript/dispatchkit/operators.hpp include/chaiscript/dispatchkit/proxy_constructors.hpp include/chaiscript/dispatchkit/proxy_functions.hpp include/chaiscript/dispatchkit/proxy_functions_detail.hpp include/chaiscript/dispatchkit/register_function.hpp include/chaiscript/dispatchkit/type_info.hpp include/chaiscript/language/chaiscript_algebraic.hpp include/chaiscript/language/chaiscript_common.hpp include/chaiscript/language/chaiscript_engine.hpp include/chaiscript/language/chaiscript_eval.hpp include/chaiscript/language/chaiscript_parser.hpp include/chaiscript/language/chaiscript_prelude.hpp include/chaiscript/language/chaiscript_prelude_docs.hpp include/chaiscript/utility/utility.hpp) + +set_source_files_properties(${Chai_INCLUDES} PROPERTIES HEADER_FILE_ONLY TRUE) + if (MULTITHREAD_SUPPORT_ENABLED) find_package(Boost 1.36.0 COMPONENTS thread) @@ -104,7 +108,7 @@ endif() include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIR}) -add_executable(chai src/main.cpp) +add_executable(chai src/main.cpp ${Chai_INCLUDES}) target_link_libraries(chai ${LIBS}) if (BUILD_SAMPLES) From 277b4eec9aee6962f30a283caf9f145285e19951 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 14 May 2012 09:22:03 -0600 Subject: [PATCH 4/5] Add failing test for short comparisons #26 --- CMakeLists.txt | 5 +++++ unittests/short_comparison_test.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 unittests/short_comparison_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f3590fb..4d3e07d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,6 +183,11 @@ if(BUILD_TESTING) target_link_libraries(eval_catch_exception_test ${LIBS}) add_test(NAME Eval_Catch_Exception_Test COMMAND eval_catch_exception_test) + add_executable(short_comparison_test unittests/short_comparison_test.cpp) + target_link_libraries(short_comparison_test ${LIBS}) + add_test(NAME short_comparison_test COMMAND short_comparison_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}) diff --git a/unittests/short_comparison_test.cpp b/unittests/short_comparison_test.cpp new file mode 100644 index 0000000..a57e39c --- /dev/null +++ b/unittests/short_comparison_test.cpp @@ -0,0 +1,29 @@ +#include + +class Test { + public: + Test() : value_(5) {} + + short get_value() { return value_; } + + short value_; +}; + +int main() +{ + + chaiscript::ChaiScript chai; + chai.add(chaiscript::user_type(), "Test"); + chai.add(chaiscript::constructor(), "Test"); + + chai.add(chaiscript::fun(&Test::get_value), "get_value"); + + chai.eval("var t := Test();"); + + if (chai.eval("t.get_value() == 5")) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } +} From b0b1549503e0f0d3a7e73fbf6e982dcf4a2d9fb7 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 14 May 2012 09:33:35 -0600 Subject: [PATCH 5/5] Fix cast for unsigned short #26 --- include/chaiscript/dispatchkit/boxed_number.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index a5f6b50..263619a 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -276,7 +276,7 @@ namespace chaiscript } else if (inp_ == typeid(boost::int8_t)) { return oper_rhs(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(boost::int16_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); + return oper_rhs(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(boost::int32_t)) { return oper_rhs(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(boost::int64_t)) {