Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
Addison Schuhardt
I've tried
  var k = Key();
But I get the error message terminate called after throwing an instance of 'chaiscript::exception::eval_error' what(): Error: "Error with function dispatch for function 'to_string'" With parameters: (Key).()
trying to access the class's attr by value var x = k.KEY_N0; throws another error
Error: "'KEY_N0' is not a function."
Maybe I'm misunderstanding what the add_class utility is supposed to be doing?
Addison Schuhardt
var k = Key.KEY_N0 throws this error:
Error: "Error with function dispatch for function 'KEY_N0'" With parameters: (const Function).(string)
What am I missing?
Addison Schuhardt
Welp. Figured it out. It adds global(?) constants. This works:
var k = KEY_N0;
in case anyone has the same question
Sam Jeeves
What's the difference currently between the vs2019 fixes and the develop branches right now? Which is more current?

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?

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?

Stefan Agartsson
I would like to create some form of code completion in my script editor. Is there a way to get all classes and methods I've registered with chaiscript?

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:

include <chaiscript/chaiscript.hpp>


auto hello = [](const std::string& aName)->std::string
    return "Hello " + aName;
chaiscript::ChaiScript chai;

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.

So I'm working with a product that utilizes chaiscript (not embeddded within C++); and I'm curious if chaiscript supports any manipulation of strings ( such as a function/method to search a string for a specific char and/or splitting a string into multiple strings)?
@0xd800 Going by the documentation, t_bv has to be constant! See: chai.add_global_const(chaiscript::const_var(somevar), "somevar"); // global const. Throws if value is non-const, throws if object exists
I haven't checked the internals, but I think constness is required because ChaiScript does some performance optimization on these variables, which it cannot do if you want the value to change during evaluation...
@curtiplas ChaiScript supports some string functions via the Extras library However, it probably not enough for the average string tasks. You will need to either hook up the STL into ChaiScript, or write your own functions.
Translate chai into c++
hi there
first time to hear chaiscript
do u guys know to use chaiscript ?
compare to lua ?
Rob Loach
I use ChaiScript. It's slower than Lua, but I find it easier to use and more powerful.
ChaiScript is now an integral part of CartoType's data import system. I wrote some brief notes here to help people use it: http://www.cartotype.com/developers/documentation/125-notes-on-chaiscript. And there are some useful links here (in the section Notes on ChaiScript): http://www.cartotype.com/developers/documentation .
do I have a shell tool like python or lua that can type some var and print it ?
Rico P
Hi there. I wanted to ask how do I correctly reset the state of chai? I want to execute a script several times and have always clean slate global namespace. I try the following but executing the script twice will raise a exception because x is already declared
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 {

    } catch (chaiscript::exception::eval_error &ee) {
      chai_message = "Error: " + ee.reason;
    } catch (...) {
      chai_message = "Unknown Error: ";
chai->set_state(default_state) doesn't seem to reset my global state
I am on version 6.1. revision ac0d7ce. The master branch currently doesnt compile with VS2019
Jean-André Santoni

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)

Jean-André Santoni
Ok, I had to do this.anim := this.anims[this.stance][this.direction] with the reference assignment
Adam Brown
I've got a frustrating crash I can't figure out. I have a chai script that loops, accepting input from the user. It uses that input as a script name, to load and run another script, and get a return code back. Some times it's the int return code, and some times it's a string that the user entered in the 2nd script?!
that 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;
    var line = readLine();
    if(line == "exit")
        running = false;
        print("Good bye.");
        var status = run(line);
        if(status == 0)
            print("Program returned error");
int ChaiOs::run(const string& path)
            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;
        cout << "Program not found" << endl;
        return 1;
Adam Brown
here's the test script it's loading:
printRaw("Test Program, type something:");

var input = readLine();
print("You entered: " + input);

return 0;
Pat Callahan
hmm.just ran into chaiscript for the first time.
Douglas Tinkham
Just ran across this. If I have a c++ app, for example a Qt gui app, I could have a text control where users write chaiscript code (or opens existing chaiscript files) that calls my C++ functions inside my app. Is this correct?
@dtinkham_gitlab , why would you do that when Qt already has a JS engine?
or, PyQt (or PySide2)
Douglas Tinkham
Why? Because I didn't know qt had js or pyqt that would do such things. I'll have a look.
Daniel Brunner
Hi, I am trying to embed chaiscript in a small microcontroller (ESP32) and I have problems while compiling
I do not have rtti, there is simply not enough space on the flash
Can I use ChaiScript without all the dynamic_casts all over the place?
Hello, I'm working on an app where users provide a script function that is executed with objects that I get from my infrastructure. Can I limit the execution time of the user's script and its memory consumption? I assume for the memory limit I can override STL in ChaiScript with a custom allocator. But I have no idea about the execution time limit. Is it possible? Thanks
Branimir Malesevic

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);
Is chaiscript dead? -- Seems no new version for 2 1/2 years.
Seems even more dead, if my question gets no response in a month.