int ChaiOs::run(const string& path)
{
if(fileExists(path))
{
try
{
auto script = loadScript(path);
int r = chai.eval<int>(script);
return r;
}
catch(chaiscript::exception::eval_error& e)
{
cout << "eval_error: " << endl << e.pretty_print();
return 1;
}
catch(chaiscript::exception::bad_boxed_cast& e)
{
cout << "bad_boxed_cast" << endl << e.what();
return 1;
}
}
else
{
cout << "Program not found" << endl;
return 1;
}
}
printRaw("Test Program, type something:");
var input = readLine();
print("You entered: " + input);
return 0;
Hi all!
I have a question regarding the chai embedded interpreter in C++. Is there any kind of environment/isolation/sandbox (milion of names) while doing eval
so that the objects/variables/functions declared inside the script reside only in the environment?
Example would be
auto script = R("
hp = 10";
def attack() { hp -= 5; }
");
chai.eval(script, env1);
chai.eval(script, env2);
chai.eval("attack()", env1);
assert.true(env1["hp"], 5);
assert.true(env2["hp"], 10);
chai.boxed_cast<SomeType>(chai.eval("v"));
auto x = SomeType()
auto a = x.property("count"); auto b = x.count
print(a.to_string() + " == " + b.to_string)