DMDScript now on D2

Adam Ruppe destructionator at gmail.com
Thu Dec 16 08:43:58 PST 2010


Dmitry Olshansky wrote:
> The goal was not only to just make it compile with D2
> and work (that would be of limited value)

I tried this too about a year ago...:
http://arsdnet.net/dcode/dmdscript_d2.zip

...but overall, from a brief glance, your port is *much* better
than mine. I used a lot more casts and idups, and thus introduced
new bugs and hurt the performance. I got it working, but not working
well.

Nice work!

But there still might be a few ideas or bits of code
we can share from the easy expansion stuff.

I called mine "pretty.d" and "test.d" in that zip. One of the
things I tried to do was make a ScriptObject class in D, which
you could expand and call with opIndex and opDispatch.

I was only partially successful, but maybe we can better with
a newer compiler.

Here's a copy/paste of part of my test.d showing the idea I was chasing:

=======
        auto g = se.globalObject; // se is a ScriptEngine

        /* You can work with the script environment as an associative
array... */
        g["hello"] = "Hello, world!";
        g["lol"] = new ScriptObject; // ScriptObject is just a generic object.
You can specialize it in the constructor.
        //g["lol"]["fun"] = &fun; // Can even assign native top-level functions
this way!  FIXME: broken due to ICE

        /* Or, you can do it with opDispatch, though this is limited to just
assigning existing ScriptObjects... */
        auto so2 = new ScriptObject;
        se.globalObject.lol.hate = so2;

        /* You can also add functions to specific ScriptObjects with the
addFunction template */
        se.addFunction!(raise, "fun")(so2);

=======

And all that stuff would of course be available to the script via
the global object.

In pretty.d, you can see some attempt to unify D and dmdscript
exceptions too, but I don't recall how well that went, but I'm
pretty sure it worked at least one way.


One little thing we both did is one line expansion. One thing I'd
add to your code is making the name of the script function default
to being the same name as the D function. It's a minor addition,
but I think it looks nice.


Generally though, your port is excellent, thanks for doing it!


More information about the Digitalmars-d-announce mailing list