leftibot 08281a9d69
Fix #146: Add configuration to bypass the registering of 'built-in' functions. (#642)
* Fix #146: Add configuration options to selectively disable built-in functions

Add new Options enum values (No_Stdlib, No_IO, No_Prelude, No_JSON) that
allow users to control which parts of the standard library are registered.
Std_Lib::library() now accepts an options vector, and the ChaiScript
convenience class forwards its options to the library builder. This enables
use cases where only custom functions should be exposed to script users.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Address review: split Options into Options and Library_Options enums

Separate system-level options (No_Load_Modules, Load_Modules, No_External_Scripts,
External_Scripts) from library-level options (No_Stdlib, No_IO, No_Prelude, No_JSON)
into two distinct enum types. Add Library_Options as a parameter to the ChaiScript
constructor. Update tests to demonstrate both ChaiScript_Basic (explicit Std_Lib::library
call) and ChaiScript (library options via constructor parameter) usage.

Requested by @lefticus in PR #642 review.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add cheatsheet documentation for Options and Library_Options

Documents the two-enum configuration system: Options (engine-level:
load_module, use, eval_file) and Library_Options (stdlib-level:
No_Stdlib, No_IO, No_Prelude, No_JSON), with usage examples for
both ChaiScript and ChaiScript_Basic constructors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 16:49:13 -06:00
.github Fix #472: Emscripten Frontend (#662) 2026-04-11 15:58:28 -06:00
cmake Move to official catch cmake support, update catch 2018-05-26 09:26:13 -06:00
contrib Remove outdated vim support 2017-11-30 10:19:56 -07:00
emscripten Fix #472: Emscripten Frontend (#662) 2026-04-11 15:58:28 -06:00
include/chaiscript Fix #146: Add configuration to bypass the registering of 'built-in' functions. (#642) 2026-04-11 16:49:13 -06:00
performance_tests change .clang-format and reformat code with clang-format 11 2021-05-24 10:44:15 +02:00
samples change .clang-format and reformat code with clang-format 11 2021-05-24 10:44:15 +02:00
src Fix #660: Windows builds are broken (#661) 2026-04-11 15:06:33 -06:00
static_libs change .clang-format and reformat code with clang-format 11 2021-05-24 10:44:15 +02:00
unittests Fix #146: Add configuration to bypass the registering of 'built-in' functions. (#642) 2026-04-11 16:49:13 -06:00
.buckconfig * Added Buck build 2017-03-08 19:47:07 +00:00
.clang-format change .clang-format and reformat code with clang-format 11 2021-05-24 10:44:15 +02:00
.decent_ci-Linux.yaml Remove g++ 4.8 from builds 2016-03-10 14:06:43 -07:00
.decent_ci-MacOS.yaml Move debug over to windows build 2016-03-05 12:04:30 -07:00
.decent_ci-Windows.yaml Merge branch 'develop' into update_travis_toolchain 2016-03-05 21:12:14 -07:00
.decent_ci.yaml Fix results location 2014-09-13 23:11:17 -06:00
.gitignore Add /build to .gitignore (#614) 2023-10-08 17:18:49 -04:00
.travis.yml Ci fix after moving to cpp17 (#455) 2018-10-20 08:50:08 -06:00
biicode.conf Update biicode and get master updated to v5.6.0 2015-03-19 20:03:12 -06:00
BUCK * Added Buckaroo.pm package 2017-07-21 11:09:53 +01:00
buckaroo.json * Added Buckaroo.pm package 2017-07-21 11:09:53 +01:00
cheatsheet.md Fix #146: Add configuration to bypass the registering of 'built-in' functions. (#642) 2026-04-11 16:49:13 -06:00
CMakeLists.txt Fix #655: Async issues with threads outliving the chaiscript engine (#656) 2026-04-11 16:12:41 -06:00
description.txt Get cpack working for source and deb distribtions. Still need to check nsis and rpm 2010-03-29 15:32:20 +00:00
DesignGoals.md Create DesignGoals.md 2016-06-28 10:34:30 -06:00
Doxyfile.in Fix Doxygen configuration 2015-01-06 13:35:52 -07:00
LICENSE license: Restore Jonathan Turner copyright 2021-05-24 16:09:20 -04:00
license.txt license: Restore Jonathan Turner copyright 2021-05-24 16:09:20 -04:00
readme.md drop link to the build dashboard 2021-05-24 23:34:54 +02:00
releasenotes.md Update release notes for 6.1.1 2019-11-09 09:44:07 -05:00
supporters.md Create supporters.md 2016-03-05 18:32:44 -07:00

Master Status: Linux Build Status Windows Build status codecov.io

Develop Status: Linux Build Status Windows Build status codecov.io

ChaiScript

http://www.chaiscript.com

(c) 2009-2012 Jonathan Turner (c) 2009-2017 Jason Turner

Release under the BSD license, see "license.txt" for details.

Introduction

Gitter

ChaiScript is one of the only embedded scripting language designed from the ground up to directly target C++ and take advantage of modern C++ development techniques, working with the developer how they would expect it to work. Being a native C++ application, it has some advantages over existing embedded scripting languages:

  1. It uses a header-only approach, which makes it easy to integrate with existing projects.
  2. It maintains type safety between your C++ application and the user scripts.
  3. It supports a variety of C++ techniques including callbacks, overloaded functions, class methods, and stl containers.

Requirements

ChaiScript requires a C++17 compiler to build with support for variadic templates. It has been tested with gcc 7 and clang 6 (with libcxx).

Installation using vcpkg

You can download and install ChaiScript using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
vcpkg install chaiscript

The ChaiScript port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Usage

  • Add the ChaiScript include directory to your project's header search path
  • Add #include <chaiscript/chaiscript.hpp> to your source file
  • Instantiate the ChaiScript engine in your application. For example, create a new engine with the name chai like so: chaiscript::ChaiScript chai
  • The default behavior is to load the ChaiScript standard library from a loadable module. A second option is to compile the library into your code, see below for an example.

Once instantiated, the engine is ready to start running ChaiScript source. You have two main options for processing ChaiScript source: a line at a time using chai.eval(string) and a file at a time using chai.eval_file(fname)

To make functions in your C++ code visible to scripts, they must be registered with the scripting engine. To do so, call add:

chai.add(chaiscript::fun(&my_function), "my_function_name");

Once registered the function will be visible to scripts as "my_function_name"

Examples

ChaiScript is similar to ECMAScript (aka JavaScript(tm)), but with some modifications to make it easier to use. For usage examples see the "samples" directory, and for more in-depth look at the language, the unit tests in the "unittests" directory cover the most ground.

For examples of how to register parts of your C++ application, see "example.cpp" in the "samples" directory. Example.cpp is verbose and shows every possible way of working with the library. For further documentation generate the doxygen documentation in the build folder or see the website http://www.chaiscript.com.

The shortest complete example possible follows:

/// main.cpp

#include <chaiscript/chaiscript.hpp>

double function(int i, double j)
{
  return i * j;
}

int main()
{
  chaiscript::ChaiScript chai;
  chai.add(chaiscript::fun(&function), "function");

  double d = chai.eval<double>("function(3, 4.75);");
}