On 16.12.2010 19:43, Adam Ruppe wrote:
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
Yes, that's the only previous effort I've found, and it was after my port almost started working.

...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!
Thanks, yet I plan a lot of refactoring, one I dream of is eventually replacing struct Value with Algebraic from Phobos. And yes, that exception propagation mechanism, I almost switched to throwing instead of returning exceptions from functions.
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);

=======
Yes, that's awesome. I guess I should get a closer look at that pretty.d!
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.

Yes, it's planned, and indeed improves user experience. I just was stuck with the issue of extending of variadic functions/templated functions consider, for example, std.stdio.writeln. That must have distracted me from this issue.


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

Dmitry Olshansky

Reply via email to