Note: This website is archived. For up-to-date information about D projects and development, please visit

A Brief Introduction of MiniD

MiniD is a language in the vein of Lua, ECMAScript (JavaScript), and Squirrel. It is dynamically typed, with a C-style syntax. Many features are taken from Lua, as it was the inspiration for MiniD. Additionally, MiniD also takes some ideas from Squirrel, such as classes, exceptions, arrays, and integral numbers. Lastly, MiniD is conceptually similar to D. Some semantics of the D language are reflected in MiniD as well.

What are some of the features?

Syntactically, it's quite similar to D or JavaScript. Here's a small snippet whose functionality should be fairly self-evident:

module demo;

// Default parameters are sugar for writing a conditional assignment of the parameter at the
// beginning of the function.  As such, if the parameter is passed the value null (i.e. if
// the function isn't passed enough parameters), it will take on the default parameter's
// value.  You can intersperse default parameters with non-default parameters, unlike in D.
function fork(x, y = 10)
	writefln("fork: ", x + y);

fork(3, 8);

// This is a table constructor.  It's something like an associative array literal.
local t =
	// This will have an index of the string "fork".
	fork = "knife",

	// This is equivalent to "foo = function() { ... }".  So again, the index will be a string.
	function foo()
	// The comma here can be elided.

	// This [expression] = expression form allows you to set values to indices with
	// arbitrary values and types.
	["while"] = 8.8

// These are two ways to access the same index; the "table.identifier" syntax is sugar
// for "table["identifier"]".

// Call the function.;

// Notice we can't write "t.while" because "while" is a keyword.

// Now for an array constructor.
local a =

// Arrays, like their D counterparts, can only be indexed by integers.

// This is accessing the "t" member.

// Let's make an array and sort it.
local a2 = [ 3, 8, 5, 6, 9, 1, 2 ];

// And then iterate.
foreach(index, value; a2)
	writefln("a2[", index, "] = ", value);

// Arrays are also dynamic.

// A test of the classes.
class Test
	mX = 0;
	mY = 0;
	mName = null;

	function constructor(name)
		mName = name;
	function position(x, y)
		mX = x;
		mY = y;
	function toString()
		return format("instance of Test: name = '%s' x = %d y = %d", mName, mX, mY);

local test = Test("hello");
test.position(4, 5);
writefln(test); // automatically calls test's toString method

One of the major goals of MiniD is also to have a very simple-to-use, almost seamless integration of scripts into the host program. This would be accomplished through an object-oriented interface coupled with templates and mixins to automate many binding tasks, such as registering a native code function to be called by MiniD code.

Here's a small feature list:

  • A grammar based off D to make it easy to switch between programming in the two languages
  • Squirrel-like classes, with support for single inheritance
  • Static function closures (return a local function, and it'll still be able to access outer local variables)
  • Cooperative multithreading through coroutines
  • A flexible module and import system, to make developing larger systems with MiniD easier

Why MiniD?

There are already several other scripting languages out there, including Lua, Python, Io, and ECMAScript. Why is MiniD around? Well, D is a new language, and a language with a lot of features not available in C. Lua, Python, and Io are all written in C, and it introduces a lot of problems. They each have their own garbage collector, which isn't part of the D GC at all. They each have their own mechanisms for handling exceptions and errors, when D provides a perfectly good mechanism of its own. And because of these reasons and because of the limited expressiveness of the C language, their APIs are fairly ugly. Squirrel is the closest relative of MiniD, but being written in C++, it's next to impossible to interface to it from D. Even if you could, it suffers from most of the same problems as the others.

There's only one other scripting language implementation that has been written in D, and as such has a more D-like interface, and that's DigitalMars' implementation of ECMAScript, called DMDScript. Unfortunately, it's not completely free for use. The commercial license requires you pay about USD$1000. Furthermore its API, while better than the C APIs of the other languages, is still not as good as it could be.

So MiniD is here for those D programmers who want a scripting language which is relatively lightweight, has a nice API, makes as much use of D constructs and idioms as possible, and is completely free. MiniD is not meant to be a fully-capable language like Python, although it does pretty well for itself as it is. It's also not meant to be a purist language or an academic language. It's a simple, practical scripting language to go with a simple, practical host language.

How far along is it?

The version 1.0 reference implementation of MiniD 1 has been released. If you want the latest release, with all kinds of bugfixes and improvements, see the main wiki page for a link.