Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
What do I have to do to make this compile?
Arthur Brainville
I use either include_directoires or target_include_directories for Chai. As it’s just a folder with a bunch of headers. Therés nothing to link against
« Link libraries » functions are for linking to .a, .lib, .so filles to your target. Nothing to do with headers.
Sure. However, that's the recommendation I found for including proper cmake projects... add_subdirectory and link against it
This helps you to include chaiscript into several projects depending on it, without duplicating the code. (Something I actually would need.)

I do it in my project like this:
Add an external_project

Just add it as a dependency to the project

As @Ybalrid already said there's nothing to link against. You just include the header files and are good to go.

I hope the code helps. Unfortunately I haven't touched the project in a while
Oliver Dain
Hey - just posted a question on the forums (http://discourse.chaiscript.com/t/chaiscript-array-of-objects-without-copy-constructor/415) and then discovered there's a chat channel too! Hoping I can get a quicker answer here as I'm kinda stuck right now. Any help would be greatly appreciated.
@StanEpp This part I did using git submodules, it works fine.

My problem is, that I have something like:

        libA/  --> uses chaiscript and spdlog
        libB/  --> uses chaiscript and spdlog
        main.cpp  --> uses libA and libB

How can I do this using cmake? In the case of other header-only libraries like spdlog, I simply write the following project file:

    cmake_minimum_required(VERSION 3.1...3.11)
    project(ace VERSION 5.0.0)
    target_link_libraries(ace PRIVATE libA)
    target_link_libraries(ace PRIVATE libB)

And inside the libraries I have:

    cmake_minimum_required(VERSION 3.1...3.11)
    project(libA VERSION 1.0.0)
    target_link_libraries(libA PRIVATE spdlog)
Rob Loach
Having a CMakeLists.txt for each folder makes your life easier. I hope to clean up some of the cmake build system in extras as an example.
That's what I did... Writing a custom CMakeLists.txt for Chaiscript. I would like to make a pull request, but I don't really know how to replace the existing one...
Arthur Brainville
Chaiscript being trader only. I never feeler the need of having to get CMake to find it i generally just set it as one of the include directories. Either on the cmake target, or even globally. I either have it copied somewhere, or included via a git submodule
Rich Henry
is the any example of returning a std::vector<int>, particularly what bindings are required?
im getting a dispatch error when i try to call .size() on it
Rob Loach
@phaistos Might have to let ChaiScript know about the vector type?
Addison Schuhardt

@RubenReijers yes it does. But it was only added to the develop branch recently. You can do the following when TerrainType is an enum class:

chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
  { { TerrainType::SOIL, "SOIL" },
    {TerrainType::PASSABLE, "PASSABLE"},
    { TerrainType::STONE, "STONE" }

Is it still possible to use enum classes this way in the current development branch?

I've tried this same method as follows:
  auto key_module = std::make_shared<chaiscript::Module>();
      *key_module, "Key",
          {Key::N0, "KEY_N0"},
          {Key::N1, "KEY_N1"},
          {Key::N2, "KEY_N2"},
          {Key::N3, "KEY_N3"},
          {Key::N4, "KEY_N4"},
I'm not sure how I'm supposed to access these values however.
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++