MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / interactive

Function interactive

src/main.cpp:229–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227}
228
229void interactive(chaiscript::ChaiScript_Basic& chai)
230{
231 using_history();
232
233 for (;;) {
234 std::string input = get_next_command();
235 try {
236 // evaluate input
237 chaiscript::Boxed_Value val = chai.eval(input);
238
239 //Then, we try to print the result of the evaluation to the user
240 if (!val.get_type_info().bare_equal(chaiscript::user_type<void>())) {
241 try {
242 std::cout << chai.eval<std::function<std::string (const chaiscript::Boxed_Value &bv)> >("to_string")(val) << '\n';
243 }
244 catch (...) {} //If we can't, do nothing
245 }
246 }
247 catch (const chaiscript::exception::eval_error &ee) {
248 std::cout << ee.what();
249 if ( !ee.call_stack.empty() ) {
250 std::cout << "during evaluation at (" << ee.call_stack[0].start().line << ", " << ee.call_stack[0].start().column << ")";
251 }
252 std::cout << '\n';
253 }
254 catch (const std::exception &e) {
255 std::cout << e.what();
256 std::cout << '\n';
257 }
258 }
259}
260
261double now()
262{

Callers 1

mainFunction · 0.70

Calls 7

bare_equalMethod · 0.80
startMethod · 0.80
using_historyFunction · 0.70
get_next_commandFunction · 0.70
evalMethod · 0.45
whatMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected