DukContext

Advanced duk context.

It allow to register D symbol directly.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

createNamespace
NamespaceContext createNamespace(string name)

Open a new JS namespace. You can then register symbol inside and call finalize() when its done.

evalString
T evalString(string js)

Evaluate a JS string and get an optional result

get
T get(int idx = -1)

Get a value on the stack.

register
DukContext register()

Automatic registration of D function. (not global)

register
DukContext register()

Automatic registration of D enum. (not global)

register
DukContext register()

Automatic registration of D class. (not global)

registerGlobal
DukContext registerGlobal(string name = Identifier!Symbol)

Register a global object in JS context.

setGlobal
DukContext setGlobal(string name)

Set a previously registered symbol as global.

Examples

1 static Point add(Point a, Point b) {
2     return new Point(a.x + b.x, a.y + b.y);
3 }
4 
5 enum Directions { up, down }
6 
7 auto ctx = new DukContext();
8 ctx.registerGlobal!add;
9 ctx.registerGlobal!Directions;
10 ctx.registerGlobal!Point;
11 
12 
13 assert(ctx.evalString!string(q"{
14     p1 = new Point(20, 40);
15     p2 = new Point(10, 20);
16     p3 = add(p1, p2);
17 
18     p3.toString();
19 }") == "(30, 60)");

Meta