April 03, 2010
On 31/03/10 13:34, Adam Ruppe wrote:
> All right, now I'm actually done for the day.
>
> Updated the zip at the link:
> http://arsdnet.net/dcode/dmdscript_d2.zip
>
> To add a pretty interface (pretty.d). It is incomplete, but works to
> play with. test.d is an example of how to use it.
>
> 	auto se = new ScriptEngine;
> 	se.addFunction!(fun, "fun");  // adding D functions is just giving
> the names. the second arg is required since stringof the alias kept
> treating it as a property.....
> 	se.addFunction!(fun2, "fun2");
> 	se.compile("function test(a) { println(a); }");
> 	se.call("test", 40); // and it is almost as easy to call script functions!
>
> When I go back to finish it, I'm thinking I'll add more integration
> with std.variant and opDispatch, so the D and javascript code
> basically work the same way.
>
>
> To do this, I did have to do one change to dmdscript itself: edited
> dnative.d to add an overload constructor so it can take a delegate as
> well as a function. That let my template just use a nested function to
> keep it easy. It might not work properly if the script tries to
> redefine the function though.
>
> Still, good enough for now. I've been at this for 9 hours! Blown my
> whole day off.
>
> On 3/30/10, Adam Ruppe<destructionator@gmail.com>  wrote:
>> On 3/29/10, Robert Clipsham<robert@octarineparrot.com>  wrote:
>>> I seem to recall it is, and a fairly old D1 at that... You could always
>>> update it and send a patch Walter's way, see if he accepts it :)
>>
>> Walter seems to have fixed it up the the new D1; it compiled there.
>>
>> And I just spent the day making a port to D2. There's a few WTFs in
>> there though, which I hacked around.
>>
>> Here it is:
>> http://arsdnet.net/dcode/dmdscript_d2.zip
>>
>> First, once each in dobject.d and script.d, I casted away a const.
>> grep for FIXME.
>>
>> Second, and this is the big one: the assocative array implementation
>> in there seems to have broken entirely with the switch to D2. Look for
>> "BIG HACK" in property.d - I had to do this two times:
>>
>> 	assert(key !is null);
>> 	p = *key in table;
>>
>> 	// BIG HACK! in seems broken!
>>          if(p is null)
>> 	foreach(k,ref v; table) {
>> 		if(k.toString() == key.toString()) {
>> 			p =&v; // WTF
>> 			break;
>> 		}
>> 	}
>>
>> Previously, it used a custom AA implementation, similar to the one in
>> Phobos, but not quite the same. It cached the hashes for boosted
>> speed.
>>
>> In phobos2, the AA implementation is completely different. This first
>> manifested itself as linker errors on foreach statements (fix it by
>> compiling as:
>>
>> dmd -oftest *.d
>>
>> instead of using the makefile). Then, I noticed obvious things were
>> failing.
>>
>> After spending a few hours on it, I decided to just give up and use
>> the above hack. I still don't understand why it is happening that way.
>> (I thought const correctness would be the hard thing, but aside from
>> the two casts, it was fairly easy. The stupid AA has been the real
>> problem!)
>>
>>
>>
>> But, anyway, it now works on some simple scripts, and the asserts in
>> there all work, so I think it is working correctly.
>>
>> Now, with it compiling as D2, the next step will be making the wrapper
>> template I mentioned yesterday. I don't have time to do it today
>> though.
>>
>> On the bright side, I know the code a bit better now than I ever did
>> before, so maybe I can make this template better than I thought! We'll
>> see.
>>



Woo! Awesome. You made my day!

n_n
1 2 3
Next ›   Last »