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

Function interactive

samples/fun_call_performance.cpp:234–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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
sizeMethod · 0.45

Tested by

no test coverage detected