Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

A rosy look at Aphid... XCopy compatible embedded scripting and more

And now for something a little different...

Today's project by John Leitch is one that I thought kind of neat in a number of ways. First, I've always liked the though of embedding scripting in my app's. Second, I like that his approach is pretty lightweight and self-contained. Finally that the source for the entire thing is included.

And even though this project is still in an Alpha state, this project will likely appeal to a number of audiences, from language builders to those just looking to add scriptability to their app's.

Making .NET Applications Scriptable with Aphid, an Embeddable Scripting Language

Aphid is an embeddable, cross-platform, multi-paradigm, and highly interoperable .NET scripting language. The Aphid interpreter is implemented entirely in C#. This article is intended to be an introduction to Aphid, and as such, only covers some of the features available. Further, Aphid is currently in an alpha state, so as it evolves, expect this article to change and grow with it. For the most recent version of Aphid, visit the CodePlex page.

What Languages is Aphid Inspired By?

Aphid is C-style language heavily inspired by JavaScript. However, it does draw from C#, and to a lesser extent, F#.

Why Another Scripting Language?

Currently, few easily embeddable scripting languages exist for the .NET platform. Among those available, many have several dependencies, necessitating the inclusion of various assemblies. Still others are lacking in interoperability, requiring inordinate amounts of wire-up code. Aphid seeks to solve these problems by providing an easily embeddable, highly interoperable scripting language contained within a single DLL.

...

Hello, World

Getting started with Aphid is rather painless. First, add a reference to Components.Aphid.dll. Next, instantiate AphidInterpreter. Finally, invoke the instance method AphidInterpreter.Interpret to execute an Aphid script. Painless, huh? A complete C#/Aphid "Hello world" program is shown below, in listing 1.

image

The C# portion of the application should be self explanatory. The Aphid program, however, warrants a bit of an explanation. The program consists of two statements.

The first is a load script statement, consisting of the load script operator (#) and the string operand, 'Std'. By default, the Aphid loader first searches the Library subdirectory of the directory in which Components.Aphid.dll resides. The loader automatically appends the ALX extension to script name passed, so in this instance it looks for <dll>\Library\Std.alx. Assuming everything is in order, it should find and load the file, which is the standard Aphid library, and contains helpful functions for manipulating strings, printing console output, etc.

The second statement is a call expression which invokes print, a function that is part of the Aphid standard library. This line of code should be rather self explanatory.

When the program is run, the output is as expected (listing 2).

image

...

Aphid

What is Aphid?

Aphid is an embeddable, cross-platform, multi-paradigm, and highly interoperable .NET scripting language.

...

What nifty features does Aphid support?

To name a few,
  • Lambda expressions
  • Partial function application
  • Pipelining
  • Pattern matching
  • Multithreading

When can I try Aphid?

Now, if you'd like. While Aphid is technically in an early, alpha state, I am currently using it in a few production systems with great success. However, the alpha implementation has some quirks, current documentation is rather minimal, as are the libraries available, and the available development tools are not yet mature.

I grabbed the latest drop (made as I write this, Saturday the 19th, so yeah, it's an active project... Wink and besides having to fix up an NUnit reference in the Components.Aphid.Tests.Integration project (NuGet is, as always, your friend in doing this), the source compiled and the samples all seemed to run as expected (which makes a code curator like me a happy camper)

Here's a snap of the Solution;

image

Besides the unit tests, there's a number of canned samples too;

image

image

One thing I found cool is that he's working on a language service to allow real integration with Visual Studio, which takes this entire project to another level...

image

SNAGHTML2eabe8

Now that's pretty cool... Head on over and get your scripting on...

 

NOTE: This project is licensed as GPLv3, so ensure you understand that license and ramifications of including a such licensed project in your work...

 

Image Credit: Augie Schwer Ladybugs

Tags:

Follow the Discussion

  • I can't think of a use case (right now Wink) but that is pretty cool!

  • Vipul S. ChawatheVSChawathe Vipul

    C & F# inspired.. I'd love IE to ship supporting this as an alternative to ecma monopoly.

  • Matthew MoloneyMatthew Moloney

    Pretty cool. This is useful for building flexible systems where end users need to customize and extend software to fit their own needs. I’ve built a similar solution around embedding F# directly. It is a fully fledged IDE complete with code completion and error underlining (tsunami.io).

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.