diff --git a/CMakeLists.txt b/CMakeLists.txt index f2f2bcd8..19dce000 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,11 @@ endif() include_directories(include) + +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) else() add_definitions(-DCHAISCRIPT_NO_THREADS) @@ -84,7 +89,7 @@ if (CMAKE_COMPILER_2005) # ADD_DEFINITIONS(/wd4244) endif() -add_executable(chai src/main.cpp) +add_executable(chai src/main.cpp ${Chai_INCLUDES}) target_link_libraries(chai ${LIBS}) if (BUILD_SAMPLES) @@ -159,6 +164,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/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 8644f8f1..13f53395 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. diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index 0241c5b3..795bac8f 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -275,7 +275,7 @@ namespace chaiscript } else if (inp_ == typeid(std::int8_t)) { return oper_rhs(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(std::int16_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); + return oper_rhs(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(std::int32_t)) { return oper_rhs(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(std::int64_t)) { diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 210661bf..8d0cd0ef 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -286,34 +286,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 chaiscript::exception::file_not_found_error &) { - if (i == m_usepaths.size() - 1) - { - throw chaiscript::exception::file_not_found_error(t_filename); - } - - // failed to load, try the next path - } - } - } - /** * Returns the current evaluation m_engine */ @@ -413,6 +385,40 @@ namespace chaiscript build_eval_system(t_lib); } + /// \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 diff --git a/unittests/short_comparison_test.cpp b/unittests/short_comparison_test.cpp new file mode 100644 index 00000000..8295f326 --- /dev/null +++ b/unittests/short_comparison_test.cpp @@ -0,0 +1,30 @@ +#include +#include + +class Test { + public: + Test() : value_(5) {} + + short get_value() { return value_; } + + short value_; +}; + +int main() +{ + + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chai.add(chaiscript::user_type(), "Test"); + chai.add(chaiscript::constructor(), "Test"); + + chai.add(chaiscript::fun(&Test::get_value), "get_value"); + + chai.eval("auto &t = Test();"); + + if (chai.eval("t.get_value() == 5")) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } +}