Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

Include Scripting Engine in Your Own Application

0.00/5 (No votes)
4 Aug 2011Apache2 min read 14.5K  
How to include a scripting engine in your own application

Have you ever thought about including a scripting engine into your application? Maybe for advanced users, or just to be able to automate some things?

Goals of a Scripting Language

So what do you expect from an scripting engine?

First of all, you want it to be simple but it should also be powerful. Experienced users should get the chance of performing advanced tasks.

Most builtin scripting languages also provide their own command set, e.g. Read/Write application configuration without parsing any file.

As we are developing in the .NET world, all this cries for using a CLR Language as scripting language, but there remains one problem.

How to Achieve Simplicity

Imagine someone just wants to output some lines to the console:

C#
public class Test
{
  static void main(string[] args)
  {
    Console.WriteLine("myText");
  }
}

That's definitely not what I would call simple!

What Do We Need to Make this Simpler?

My idea of solving this situation works as follows:

  1. Eliminate the need to write class and method definitions

    Just write:

    C#
    Console.WriteLine("myText");

    This will be automatically embedded into a class and method definition.

  2. Provide the possibility to include user written methods and classes

    For simple tasks, the overhead is minimized and more advanced users can still show what they can. ;-)

  3. Provide the possibility to register custom methods and properties

    They are directly usable from the user script. See TestEnvironment of DevEck.ScriptingEngine.

Check Out the Scripting Engine and Example Application

I implemented the mentioned things and attached the library with a simple test projects. The test project accepts VB.NET code, but you can switch to C#. I currently use it in a highly database enabled application for automating SQL Queries.

If you like it, please leave me a comment.

Update 14.01.2010

  • I moved the source to github, browse to http://github.com/deveck to see my other projects.
  • To clone the source, do the following:

    Code:

    git clone git://github.com/deveck/dotNet_ScriptingEngine.git
  • If you are not familiar with git, have a look at http://help.github.com/.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0