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

Version: 3.1.0 Released: 6/18/2011

Source (tar.bz2)
Source (zip)
Windows
Linux
MacOSX

Define new operators?

Hi, great library!

Is it possible to create new operators, e.g. support something like

> if ("CAR" contains "C)

Have "contains" as a new operator point to a C++ function bool Contains(stringA, stringB)

thanks

Thanks, glad you like it! We

Thanks, glad you like it!

We did at one time consider allowing any function with two arguments to be usable as an infix operator as you show, but it ended up being too difficult to manage in the end. The changes it would require to the parser make it unlikely that we will allow that in the future.

Of course, you can override any (well most) C operators, so you might be able to find something that works for you there. Example:

def string::&(rhs)
{
  return this.find(rhs) != -1;
}
 
if ("CAR" & "C")
{
 ...
}

-Jason