2013-03-28 21:59:36 -06:00
contrib Correct broken unit test for vector of suffixed numbers 2013-02-23 21:27:01 -07:00
include/chaiscript Merge branch 'master' of https://github.com/ChaiScript/ChaiScript 2013-03-28 21:18:44 -06:00
samples Eradicate global base_class registrations to prevent problems with threading and general memory management issues with knowing how and when to clean them up. 2013-02-25 11:00:14 -07:00
src Add example of wrapping data members of a class #79 2013-02-24 15:11:06 -07:00
unittests Eradicate global base_class registrations to prevent problems with threading and general memory management issues with knowing how and when to clean them up. 2013-02-25 11:00:14 -07:00
CMakeLists.txt Do not link dl if on FreeBSD 2013-03-28 21:59:36 -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
Doxyfile.in More documentation updates. 2011-04-04 07:08:28 -06:00
license.txt Update copyrights to 2012 #23 2012-05-16 11:55:51 -06:00
readme.md Update readme.txt to readme.md for better formatting. 2012-08-14 12:00:44 -06:00
releasenotes.txt Update version to 4.2.0 2012-11-30 20:38:17 -07:00

ChaiScript

http://www.chaiscript.com

(c) 2009-2012 Jason Turner and Jonathan Turner

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

Introduction

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 like he expects 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 recent version of Boost (http://www.boost.org) to build.

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

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 "src" 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);");
}