void do_work(chaiscript::ChaiScript &c, int id) { try{ std::stringstream ss; ss << "MyVar" << rand(); c.add(chaiscript::var(5), ss.str()); ss.str(""); ss << id; c.use("multithreaded_work.inc"); c("do_chai_work(4000, " + ss.str() + ");"); } catch (const std::exception &e) { std::cout << "exception: " << e.what() << " thread: " << id; } }
void interactive(chaiscript::ChaiScript& chai) { using_history(); for (;;) { std::string input = get_next_command(); try { // evaluate input chaiscript::Boxed_Value 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<void>())) { try { std::cout << chai.eval<std::function<std::string(const chaiscript::Boxed_Value &bv)> >("to_string")(val) << std::endl; } catch (...) {} //If we can't, do nothing } } catch (const chaiscript::exception::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 (const std::exception &e) { std::cout << e.what(); std::cout << std::endl; } } }
void do_work(chaiscript::ChaiScript &c) { // c("use(\"work.chai\"); do_chai_work(num_iterations);"); std::string name = "MyVar" + boost::lexical_cast<std::string>(rand()); c.add(chaiscript::var(5), name); c("use(\"work.chai\"); do_chai_work(10000);"); }
void RunFile(std::string sFile) { try { chaiscript::Boxed_Value val = chai.eval_file(sFile); } catch (std::exception &e) { std::cout << e.what() << '\n'; } }
void ResetState() { chai.set_state(backupState); chai.add(chaiscript::fun(&function),"Whatever()"); }