Eko: New Programming language write entirely in D (Feedback welcome)
Adam D. Ruppe
destructionator at gmail.com
Sat Aug 22 01:04:40 UTC 2026
On Friday, 21 August 2026 at 18:25:43 UTC, pouya1dev wrote:
> I think that windows could not be combined into a hash map.
It should be possible but idk how your script language works.
Simpledisplay assumes D templates are available but you can make
a few wrapper functions too for assigning events.
> It is really interesting that it even has a scripting language.
> Do you have more information about it? Or if possible, could
> you put a link to the project's GitHub?
all the public arsd stuff is in the same github,
github.com/adamdruppe/arsd there are about 100 different libs as
files in the one repo.
If you use dub you have to list the pieces separately though, i
think it is called "arsd-official:script" there.
My script language exists mostly just to blur the line between
compiled D and the eval script. I wanted to see how close they
could get. Its interpreter is in the script.d file and the data
structure is in the jsvar.d file.
Let me show you a little demo:
```
import arsd.simpledisplay;
import arsd.script;
void main() {
var scriptGlobals = var.emptyObject;
// you can expose functions to the script by assigning
them to the globals
scriptGlobals.writeln = (var a) { import arsd.core;
writeln(a); };
// for objects, there are two options, one is a class
with explicitly marked
// scriptable methods like this one:
static class PainterWrapper {
private ScreenPainter p;
private this(ScreenPainter p) {
this.p = p;
}
@scriptable:
void setFillColor(string s) { p.fillColor =
Color.fromString(s);};
void drawRectangle(int x, int y, int w, int h) {
p.drawRectangle(Point(x, y), Size(w, h)); }
void clear() { p.clear(); }
}
// and the other is to mark them as "subclassable" which
lets the script override
// its methods and create its own instances
static class SimpleWindow {
arsd.simpledisplay.SimpleWindow wrappedWindow;
this() { wrappedWindow = new
arsd.simpledisplay.SimpleWindow; }
void close() { wrappedWindow.close(); }
void eventLoop() { wrappedWindow.eventLoop(50,
&onTimerInternal, &onChar); }
void onChar(dchar s) {}
void onTimer() { }
void paint(PainterWrapper p) {}
private void onTimerInternal() {
this.onTimer();
scope pw = new
PainterWrapper(wrappedWindow.draw());
this.paint(pw);
}
}
scriptGlobals.SimpleWindow = subclassable!SimpleWindow;
// once you set up your initial globals, you pass it to
interpret along with a script string
// (which can be at runtime, of course) to run it
interpret(`
var frameCounter = 0;
var window = new SimpleWindow();
window.onChar = function(c) {
writeln(c);
};
window.onTimer = function() {
frameCounter += 1;
};
window.paint = function(painter) {
painter.clear();
painter.setFillColor("green");
painter.drawRectangle(frameCounter % 500,
0, 100, 100);
};
window.eventLoop();
`, scriptGlobals);
}
```
When it works, it is kinda cool, this will make a green rectangle
slowly moving right across the window.
When it doesn't work, you will get some pretty ugly error
messages and good luck making sense of them lol.
More information about the Digitalmars-d
mailing list