var k = Key();
print(k.KEY_N0);
terminate called after throwing an instance of 'chaiscript::exception::eval_error'
what(): Error: "Error with function dispatch for function 'to_string'" With parameters: (Key).()
var x = k.KEY_N0;
throws another error
Error: "'KEY_N0' is not a function."
chaiscript::exception::global_non_const If t_bv is not a constant object
Does it mean that t_bv should be const-qualified or just that I shouldn't ever modify it?
Moreover,
ChaiScript_Basic& chaiscript::ChaiScript_Basic::add_global_const ( const Boxed_Value & t_bv,
const std::string & t_name
)
it is const& in signature.
I am confused. Can someone elaborate?
I don't understand the distinction between the normal and the static-library versions of ChaiScript. I watched Jason's Intro To ChaiScript video, which showed him compiling normally in Linux, getting a library load error, then correcting the error by compiling using the static-lib constructor argument; but when I try a simple example using the normal version in Windows, it works correctly without the need to create any dynamically loaded library. Here's my sample code, which includes the main chaiscript header and adds no other chaiscript source code files:
...
auto hello = [](const std::string& aName)->std::string
{
return "Hello " + aName;
};
chaiscript::ChaiScript chai;
chai.add(chaiscript::fun(hello),"hello");
chai.eval("puts(hello(\"Graham\"))");
So I assume there's a difference between the way this library-loading system works under Windows and on other platforms. It would be great to have an explanation.
static std::string chai_message = "";
static chaiscript::ChaiScript::State default_state;
void ros_print(const std::string &s) { chai_message = s; }
std::string helloWorld(const std::string &t_name) { return "Hello " + t_name + "!"; }
ChaiSystem::ChaiSystem() : chai(nullptr) {}
void ChaiSystem::initialize() {
chai = new chaiscript::ChaiScript();
chai->add(chaiscript::fun(&helloWorld), "helloWorld");
chai->add(chaiscript::fun(&ros_print), "ros_print");
default_state = chai->get_state();
}
void ChaiSystem::execute() {
static char script[16 * 1024] = "var x= 1\nros_print(helloWorld(\" Bob \"));";
try {
chai->set_state(default_state);
chai->eval(script);
} catch (chaiscript::exception::eval_error &ee) {
chai_message = "Error: " + ee.reason;
throw;
} catch (...) {
chai_message = "Unknown Error: ";
}
}
chai->set_state(default_state)
doesn't seem to reset my global state
Hi, I'm trying to do a double map like this:
this.anims = [
"stand": [
"left": Animation(love.graphics.newImage("assets/bomberman_stand_left.png"), 24, 24, 0.2f),
"right": Animation(love.graphics.newImage("assets/bomberman_stand_right.png"), 24, 24, 0.2f),
"up": Animation(love.graphics.newImage("assets/bomberman_stand_up.png"), 24, 24, 0.2f),
"down": Animation(love.graphics.newImage("assets/bomberman_stand_down.png"), 24, 24, 0.2f)
],
"walk": [
"left": Animation(love.graphics.newImage("assets/bomberman_walk_left.png"), 24, 24, 0.2f),
"right": Animation(love.graphics.newImage("assets/bomberman_walk_right.png"), 24, 24, 0.2f),
"up": Animation(love.graphics.newImage("assets/bomberman_walk_up.png"), 24, 24, 0.2f),
"down": Animation(love.graphics.newImage("assets/bomberman_walk_down.png"), 24, 24, 0.2f)
]
]
this.anim = this.anims[this.stance][this.direction]
But I'm getting this error: Error: "Missing clone or copy constructor for right hand side of equation" With parameters: (Image)
var status
is some times an int, and some times a string, and it should always be an int
run()
is a C++ function that always returns an int, and internally does an eval()
on a script
var running = true;
while(running)
{
printRaw("/");
var line = readLine();
if(line == "exit")
{
running = false;
print("Good bye.");
}
else
{
var status = run(line);
print(status);
if(status == 0)
{
print("Success");
}
else
{
print("Program returned error");
}
}
}
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);