Merge branch 'master' into 2011-09-09-CxScript

Conflicts:
	CMakeLists.txt
	include/chaiscript/dispatchkit/boxed_number.hpp
	include/chaiscript/language/chaiscript_engine.hpp
This commit is contained in:
Jason Turner
2012-05-14 10:08:04 -06:00
5 changed files with 78 additions and 32 deletions

View File

@@ -68,6 +68,11 @@ endif()
include_directories(include) 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) if (MULTITHREAD_SUPPORT_ENABLED)
else() else()
add_definitions(-DCHAISCRIPT_NO_THREADS) add_definitions(-DCHAISCRIPT_NO_THREADS)
@@ -84,7 +89,7 @@ if (CMAKE_COMPILER_2005)
# ADD_DEFINITIONS(/wd4244) # ADD_DEFINITIONS(/wd4244)
endif() endif()
add_executable(chai src/main.cpp) add_executable(chai src/main.cpp ${Chai_INCLUDES})
target_link_libraries(chai ${LIBS}) target_link_libraries(chai ${LIBS})
if (BUILD_SAMPLES) if (BUILD_SAMPLES)
@@ -159,6 +164,11 @@ if(BUILD_TESTING)
target_link_libraries(eval_catch_exception_test ${LIBS}) target_link_libraries(eval_catch_exception_test ${LIBS})
add_test(NAME Eval_Catch_Exception_Test COMMAND eval_catch_exception_test) 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 add_executable(multifile_test unittests/multifile_test_main.cpp unittests/multifile_test_chai.cpp
unittests/multifile_test_module.cpp) unittests/multifile_test_module.cpp)
target_link_libraries(multifile_test ${LIBS}) target_link_libraries(multifile_test ${LIBS})

View File

@@ -192,8 +192,8 @@
/// Overloaded methods will need some help, to hint the compiler as to which overload you want: /// Overloaded methods will need some help, to hint the compiler as to which overload you want:
/// ///
/// \code /// \code
/// chai.add(fun<void (MyClass::*)()>(&MyClass::overloadedmethod), "overloadedmethod")); /// chai.add(fun<void (MyClass::*)()>(&MyClass::overloadedmethod), "overloadedmethod");
/// chai.add(fun<void (MyClass::*)(const std::string &)>(&MyClass::overloadedmethod, "overloadedmethod")); /// chai.add(fun<void (MyClass::*)(const std::string &)>(&MyClass::overloadedmethod), "overloadedmethod");
/// \endcode /// \endcode
/// ///
/// There are also shortcuts built into chaiscript::fun for binding up to the first two parameters of the function. /// There are also shortcuts built into chaiscript::fun for binding up to the first two parameters of the function.

View File

@@ -275,7 +275,7 @@ namespace chaiscript
} else if (inp_ == typeid(std::int8_t)) { } else if (inp_ == typeid(std::int8_t)) {
return oper_rhs<std::int8_t, false>(t_oper, t_lhs, t_rhs); return oper_rhs<std::int8_t, false>(t_oper, t_lhs, t_rhs);
} else if (inp_ == typeid(std::int16_t)) { } else if (inp_ == typeid(std::int16_t)) {
return oper_rhs<std::int32_t, false>(t_oper, t_lhs, t_rhs); return oper_rhs<std::int16_t, false>(t_oper, t_lhs, t_rhs);
} else if (inp_ == typeid(std::int32_t)) { } else if (inp_ == typeid(std::int32_t)) {
return oper_rhs<std::int32_t, false>(t_oper, t_lhs, t_rhs); return oper_rhs<std::int32_t, false>(t_oper, t_lhs, t_rhs);
} else if (inp_ == typeid(std::int64_t)) { } else if (inp_ == typeid(std::int64_t)) {

View File

@@ -286,34 +286,6 @@ namespace chaiscript
return do_eval(t_e, "__EVAL__", true); 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<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex);
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> 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 * Returns the current evaluation m_engine
*/ */
@@ -413,6 +385,40 @@ namespace chaiscript
build_eval_system(t_lib); 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<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex);
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> 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 /// \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_bv Boxed_Value to add as a global
/// \param[in] t_name Name of the value to add /// \param[in] t_name Name of the value to add

View File

@@ -0,0 +1,30 @@
#include <chaiscript/utility/utility.hpp>
#include <chaiscript/chaiscript_stdlib.hpp>
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>(), "Test");
chai.add(chaiscript::constructor<Test()>(), "Test");
chai.add(chaiscript::fun(&Test::get_value), "get_value");
chai.eval("auto &t = Test();");
if (chai.eval<bool>("t.get_value() == 5"))
{
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
}
}