Reply to comment

ChaiScript: Easy C++ Scripting

Jon and I released the first release of ChaiScript earlier today. ChaiScript is designed to make it trivially easy to use scripting in your C++ application and to expose your C++ to the scripting system.

ChaiScript is a header only implementation. It requires no external libraries and is distributed under the BSD license, making it free and easy to distribute.

So, how easy is easy, really? How does 3 lines of code sound for a classic hello world example?

#include <iostream> 
#include <chaiscript/chaiscript.hpp>
 
int main(int argc, char *argv[]) 
{
  chaiscript::ChaiScript_Engine chai;
  chai.evaluate_string("print('Hello World');");
}

Of course, this example is quite limited in usefulness. But I want to keep this article short and not get into too much detail. So, I will provide on more example that shows how to expose a C++ function to ChaiScript.

#include <iostream> 
#include <chaiscript/chaiscript.hpp>
 
std::string get_message()
{
  return "Hello World";
}
 
int main(int argc, char *argv[]) 
{
  chaiscript::ChaiScript_Engine chai;
  dispatchkit::register_function(chai.get_eval_engine(), &get_message, "get_message");
  chai.evaluate_string("print(get_message());");
}

ChaiScript never gets much more difficult than that. Stay tuned for more ideas, or check out the The Book of ChaiScript for more information.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post PHP code. You should include <?php ?> tags.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.