diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 5ee324c..7dbb921 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -156,8 +156,8 @@ namespace chaiscript detail::Get_Type_Info::get(), boost::any(obj), false, - &Data::unique, - &Data::is_null) + boost::function(&Data::unique), + boost::function(&Data::is_null)) ); std::map::iterator itr @@ -219,8 +219,8 @@ namespace chaiscript detail::Get_Type_Info::get(), boost::any(boost::shared_ptr(new T(t))), false, - &Data::unique, - &Data::is_null) + boost::function(&Data::unique), + boost::function(&Data::is_null)) ); boost::shared_ptr *ptr = boost::any_cast >(&data->m_obj); diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 124f714..ba190f5 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -287,8 +287,9 @@ namespace chaiscript Bound_Function(const Const_Proxy_Function &t_f, const std::vector &t_args) : Proxy_Function_Base(std::vector()), - m_f(t_f), m_args(t_args), m_arity(m_f->get_arity()<0?-1:(m_f->get_arity() - m_args.size())) + m_f(t_f), m_args(t_args), m_arity(m_f->get_arity()<0?-1:(m_f->get_arity() - static_cast(m_args.size()))) { + assert(m_f->get_arity() >= static_cast(m_args.size())); } virtual bool operator==(const Proxy_Function_Base &) const diff --git a/src/main.cpp b/src/main.cpp index 94c4f27..e46cb9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,10 +18,10 @@ #include void print_help() { - std::cout << "ChaiScript evaluator. To evaluate an expression, type it and press ." << std::endl; - std::cout << "Additionally, you can inspect the runtime system using:" << std::endl; - std::cout << " dump_system() - outputs all functions registered to the system" << std::endl; - std::cout << " dump_object(x) - dumps information about the given symbol" << std::endl; + std::cout << "ChaiScript evaluator. To evaluate an expression, type it and press ." << std::endl; + std::cout << "Additionally, you can inspect the runtime system using:" << std::endl; + std::cout << " dump_system() - outputs all functions registered to the system" << std::endl; + std::cout << " dump_object(x) - dumps information about the given symbol" << std::endl; } @@ -39,125 +39,129 @@ bool throws_exception(const chaiscript::Proxy_Function &f) std::string get_next_command() { #ifdef READLINE_AVAILABLE - char *input_raw; - input_raw = readline("eval> "); - add_history(input_raw); - return std::string(input_raw); + char *input_raw; + input_raw = readline("eval> "); + add_history(input_raw); + return std::string(input_raw); #else - std::string retval; - std::cout << "eval> "; - std::getline(std::cin, retval); - return retval; + std::string retval; + std::cout << "eval> "; + std::getline(std::cin, retval); + return retval; #endif } +void myexit(int return_val) { + exit(return_val); +} + int main(int argc, char *argv[]) { - std::string input; + std::string input; - std::vector usepaths; - std::vector modulepaths; + std::vector usepaths; + std::vector modulepaths; - // Disable deprecation warning for getenv call. + // Disable deprecation warning for getenv call. #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable : 4996) #endif - const char *usepath = getenv("CHAI_USE_PATH"); - const char *modulepath = getenv("CHAI_MODULE_PATH"); + const char *usepath = getenv("CHAI_USE_PATH"); + const char *modulepath = getenv("CHAI_MODULE_PATH"); #ifdef BOOST_MSVC #pragma warning(pop) #endif - - usepaths.push_back(""); - if (usepath) - { - usepaths.push_back(usepath); - } + usepaths.push_back(""); - modulepaths.push_back(""); + if (usepath) + { + usepaths.push_back(usepath); + } - if (modulepath) - { - modulepaths.push_back(modulepath); - } + modulepaths.push_back(""); + + if (modulepath) + { + modulepaths.push_back(modulepath); + } - chaiscript::ChaiScript chai(modulepaths,usepaths); + chaiscript::ChaiScript chai(modulepaths,usepaths); - chai.add(chaiscript::fun(&exit), "exit"); - chai.add(chaiscript::fun(&throws_exception), "throws_exception"); + chai.add(chaiscript::fun(&myexit), "exit"); + chai.add(chaiscript::fun(&throws_exception), "throws_exception"); - if (argc < 2) { + if (argc < 2) { #ifdef READLINE_AVAILABLE - using_history(); + using_history(); #endif - input = get_next_command(); - while (input != "quit") { + input = get_next_command(); + while (input != "quit") { - chaiscript::Boxed_Value val; + chaiscript::Boxed_Value val; - if (input == "help") { - print_help(); - } - else { - try { - //First, we evaluate it - val = chai.eval(input); + if (input == "help") { + print_help(); + } + else { + try { + //First, we evaluate it + val = chai.eval(input); - //Then, we try to print the result of the evaluation to the user - if (!val.get_type_info().bare_equal(chaiscript::user_type())) { - try { - chaiscript::dispatch(chai.get_eval_engine().get_function("print"), chaiscript::Param_List_Builder() << val); - } - catch (...) { - //If we can't, do nothing - } - } - } - catch (chaiscript::Eval_Error &ee) { - std::cout << ee.what(); - if (ee.call_stack.size() > 0) { - std::cout << "during evaluation at (" << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")"; - } - std::cout << std::endl; - } - catch (std::exception &e) { - std::cout << e.what(); - std::cout << std::endl; - } - } - - input = get_next_command(); - } - } - else { - for (int i = 1; i < argc; ++i) { + //Then, we try to print the result of the evaluation to the user + if (!val.get_type_info().bare_equal(chaiscript::user_type())) { try { - chaiscript::Boxed_Value val = chai.eval_file(argv[i]); + chaiscript::dispatch(chai.get_eval_engine().get_function("print"), chaiscript::Param_List_Builder() << val); } - catch (chaiscript::Eval_Error &ee) { - std::cout << ee.what(); - if (ee.call_stack.size() > 0) { - std::cout << "during evaluation at (" << ee.call_stack[0]->filename << " " << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")"; - for (unsigned int j = 1; j < ee.call_stack.size(); ++j) { - std::cout << std::endl; - std::cout << " from " << ee.call_stack[j]->filename << " (" << ee.call_stack[j]->start.line << ", " << ee.call_stack[j]->start.column << ")"; - } - } - std::cout << std::endl; - return EXIT_FAILURE; - } - catch (std::exception &e) { - std::cout << e.what() << std::endl; - return EXIT_FAILURE; + catch (...) { + //If we can't, do nothing } + } } - } + catch (chaiscript::Eval_Error &ee) { + std::cout << ee.what(); + if (ee.call_stack.size() > 0) { + std::cout << "during evaluation at (" << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")"; + } + std::cout << std::endl; + } + catch (std::exception &e) { + std::cout << e.what(); + std::cout << std::endl; + } + } - return EXIT_SUCCESS; + input = get_next_command(); + } + } + else { + for (int i = 1; i < argc; ++i) { + try { + chaiscript::Boxed_Value val = chai.eval_file(argv[i]); + } + catch (chaiscript::Eval_Error &ee) { + std::cout << ee.what(); + if (ee.call_stack.size() > 0) { + std::cout << "during evaluation at (" << ee.call_stack[0]->filename << " " << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")"; + for (unsigned int j = 1; j < ee.call_stack.size(); ++j) { + std::cout << std::endl; + std::cout << " from " << ee.call_stack[j]->filename << " (" << ee.call_stack[j]->start.line << ", " << ee.call_stack[j]->start.column << ")"; + } + } + std::cout << std::endl; + return EXIT_FAILURE; + } + catch (std::exception &e) { + std::cout << e.what() << std::endl; + return EXIT_FAILURE; + } + } + } + + return EXIT_SUCCESS; }