About ChaiScript

ChaiScript is the first and only scripting language designed from the ground up with C++ compatibility and modern design in mind. It is an ECMAScript-inspired, embedded functional-like language.

ChaiScript is licensed under the BSD license.

Download

Due to an increased release schedule, and the nature of ChaiScript being a header-only library, binary releases will be made less often. Previous releases can be found on github.

Version: 4.2.0 Released: 12/1/2012
(Requires Boost)
Source (tar.bz2)
Source (zip)

Version: 5.2.0 Released: 12/1/2012
(Requires C++11 Compiler)
Source (tar.bz2)
Source (zip)

Mapping C++ templates to ChaiScript

As some people already wrote - ChaiScript help as a single, for example pdf, printable document would be very appreciated. It's very important for people starting with ChaiScript to have overall picture from the beginning.

Now a question about C++ templates.

If I have C++ class A<T>, should I map (define conversion C++ --> ChaiScript) any used T type separately:
A<int>, A<double>, ..., fun<int>(), fun<double>(), ...
or there is a way to define mapping for set of types instead of separate mapping for every type manually ?

Sorry for the slow

Sorry for the slow response.

You do have to map each type separately, however, you can set up a template for you to do it:

template<typename T>
void register_my_class(ChaiScript &t_chai, const std::string &t_name)
{
  t_chai.add(chaiscript::user_type(T), t_name);
  t_chai.add(fun(&T::fun1), "fun1");
  t_chai.add(fun(&T::fun2), "fun2");
}

Because of the nature of templates, there's simply no way around this. You cannot generically export a template to the scripting engine, because the compiler needs to generate the instantiations you want to use at compile time.

This technique described above is used in the ChaiScript bootstrap code. Example: https://github.com/ChaiScript/ChaiScript/blob/master/include/chaiscript/...

template types

Yes I would like to ask the same question. I am trying to script a Math library that is "templated" mainly for precision purpose (float / double).

Instead of writing several mappings, it would be great to have a macro of some form where the typical template type(s) can be passed along with class/function registration details.

anybody ...

If this is not a feature available then can this be taken up as a feature request please. Thanks.

Support ChaiScript by sharing it with your friends: