digitalmars.D - Scripting again.
- so (17/17) Dec 09 2010 Hello!
- Simen kjaeraas (5/19) Dec 09 2010 Mostly, there is no D compiler written in D that can be included in the
- so (10/10) Dec 09 2010 This is the only reason i can think of too.
- Andrei Alexandrescu (4/23) Dec 09 2010 A system() call should work as well. A larger problem is dynamically
- so (4/6) Dec 09 2010 For that to work, host needs a language environment installed.
- Jesse Phillips (5/11) Dec 09 2010 You add a scripting language to your program for two reasons. You want t...
- so (17/24) Dec 09 2010 I agree there are some handy tools, but they exist because of the
- Jesse Phillips (2/16) Dec 09 2010 How is this different from using dynamic libraries? Surely you don't thi...
- so (15/17) Dec 09 2010 For dynamic libraries it is different, everything lies at the definition...
- Jesse Phillips (6/17) Dec 09 2010 Ok, but then you also have
- %u (7/22) Dec 09 2010 Doesn't this work??
- so (3/9) Dec 09 2010 What is this supposed to mean?
- %u (18/27) Dec 09 2010 This should be a bit more clear (untested code).
- Daniel Gibson (3/34) Dec 09 2010 That wouldn't be just a script but a runtime-string-mixin (or something ...
- %u (6/40) Dec 09 2010 how about something like this:
- Daniel Gibson (20/61) Dec 09 2010 I guess something like that is possible.
- %u (6/25) Dec 09 2010 Of course, I was thinking that if you omit the function name it would de...
- Adam Ruppe (4/7) Dec 09 2010 We can do that today - write an opDispatch that forwards
- Daniel Gibson (3/12) Dec 09 2010 Cool.
- so (13/32) Dec 09 2010 The actual use case in my scenario is manipulating your program. not
- Daniel Gibson (6/42) Dec 09 2010 I think for a proper general purpose scripting solution (like one would ...
- so (8/10) Dec 09 2010 Oh you are right, supporting one side is a dead end.
- so (5/22) Dec 09 2010 Oh, D doesn't have a scripting module as far as i know.
- %u (3/26) Dec 09 2010 I was kind of implying the script module existed, but I'm not really tou...
Hello! In D, it is much harder to say something is impossible to implement comparing to other languages. If you are coming from C/C++ land, you should know that if you want to script your program, you are going to fall back to another language, possibly a "scripting" language. But why? why should i fall back to a dummy language for this? Tons of workarounds to export stuff, it is just a mess! It doesn't matter if we have tools like boost python bindings or PyD, it is still ugly. All i can see right now is the lack of compile(file, module dependencies, ...). Is it just technical limitations or is this is another religious issue? Thanks! -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 09 2010
so <so so.do> wrote:Hello! In D, it is much harder to say something is impossible to implement comparing to other languages. If you are coming from C/C++ land, you should know that if you want to script your program, you are going to fall back to another language, possibly a "scripting" language. But why? why should i fall back to a dummy language for this? Tons of workarounds to export stuff, it is just a mess! It doesn't matter if we have tools like boost python bindings or PyD, it is still ugly. All i can see right now is the lack of compile(file, module dependencies, ...). Is it just technical limitations or is this is another religious issue?Mostly, there is no D compiler written in D that can be included in the standard library. -- Simen
Dec 09 2010
This is the only reason i can think of too. The trouble with this as far as i can see is that when you have this feature (compile), you actually dictate that a D implementation must be free(?). Thinking about this, this is not something wrong. A compiler is not an ordinary program. As an OS provider, if you implement a language you are doing it for your own sake, and the profit is quite big. -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 09 2010
On 12/9/10 12:25 PM, Simen kjaeraas wrote:so <so so.do> wrote:A system() call should work as well. A larger problem is dynamically executing functions that have just been compiled. AndreiHello! In D, it is much harder to say something is impossible to implement comparing to other languages. If you are coming from C/C++ land, you should know that if you want to script your program, you are going to fall back to another language, possibly a "scripting" language. But why? why should i fall back to a dummy language for this? Tons of workarounds to export stuff, it is just a mess! It doesn't matter if we have tools like boost python bindings or PyD, it is still ugly. All i can see right now is the lack of compile(file, module dependencies, ...). Is it just technical limitations or is this is another religious issue?Mostly, there is no D compiler written in D that can be included in the standard library.
Dec 09 2010
A system() call should work as well. A larger problem is dynamically executing functions that have just been compiled.For that to work, host needs a language environment installed. Or maybe you mean distributing compiler with the project? -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 09 2010
so Wrote:Hello! All i can see right now is the lack of compile(file, module dependencies, ...). Is it just technical limitations or is this is another religious issue? Thanks!You add a scripting language to your program for two reasons. You want to make your program expendable after release or you want to change behavior during run time. These goals can be achieved with dynamic linking. This would require having a compiler to the language (some language have libraries for this) and possibly other issues. I'm of the opinion that languages like Lua/MiniD are great ways to achieve these goals as they are small efficient languages and were made specifically for embedding. I'm considering the idea of using Lua scripts as configuration files, but haven't yet put into practice to judge if it is beneficial. I do not believe it is common to add scripting to avoid the language you are writing code in.
Dec 09 2010
I'm of the opinion that languages like Lua/MiniD are great ways to achieve these goals as they are small efficient languages and were made specifically for embedding. I'm considering the idea of using Lua scripts as configuration files, but haven't yet put into practice to judge if it is beneficial.I agree there are some handy tools, but they exist because of the shortcomings of said languages, not because it is the way it should be. // define here class A { ... } // and export somewhere export(A); export(A.method); ... export(that); export(whatever); ... You see how stupid is this? How ugly it can get? For actually zero gain?I do not believe it is common to add scripting to avoid the language you are writing code in.Absolutely! -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 09 2010
so Wrote:// define here class A { ... } // and export somewhere export(A); export(A.method); ... export(that); export(whatever); ... You see how stupid is this? How ugly it can get? For actually zero gain?How is this different from using dynamic libraries? Surely you don't think plug-ins are a zero gain?
Dec 09 2010
How is this different from using dynamic libraries?For dynamic libraries it is different, everything lies at the definition, there is nothing annoying there. --- export function() { ... } --- That is it! All you need is here.Surely you don't think plug-ins are a zero gain?I guess i wasn't clear with "zero gain". The gain of scripting your program is grand. But falling back to a dummy language for this is zero gain. You don't fall back to another language to use a dynamic library. For scripting, you use another language mostly because you have to. -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 09 2010
so Wrote:Ok, but then you also have external function(); In the DLL, I think... And if you are importing a function from a DLL there is still some wrapper code that goes with it. And from your previous example you would still need the source for the class available so that you could build the DLL.How is this different from using dynamic libraries?For dynamic libraries it is different, everything lies at the definition, there is nothing annoying there. --- export function() { ... } ---But falling back to a dummy language for this is zero gain. You don't fall back to another language to use a dynamic library. For scripting, you use another language mostly because you have to.I guess I can't disagree with your main point. I couldn't think of a reason you would use python then do scripting in Lua. Of course people do some weird things: http://www.equi4.com/wikis/lua/25
Dec 09 2010
== Quote from so (so so.do)'s articleHello! In D, it is much harder to say something is impossible to implement comparing to other languages. If you are coming from C/C++ land, you should know that if you want to script your program, you are going to fall back to another language, possibly a "scripting" language. But why? why should i fall back to a dummy language for this? Tons of workarounds to export stuff, it is just a mess! It doesn't matter if we have tools like boost python bindings or PyD, it is still ugly. All i can see right now is the lack of compile(file, module dependencies, ...). Is it just technical limitations or is this is another religious issue? Thanks!Doesn't this work?? import std.file; import std.script; Script s = new Script(cast(ubyte[]) read("script1.d")); s.compile(); s.execute();
Dec 09 2010
Doesn't this work?? import std.file; import std.script; Script s = new Script(cast(ubyte[]) read("script1.d")); s.compile(); s.execute();What is this supposed to mean? -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 09 2010
== Quote from so (so so.do)'s articleThis should be a bit more clear (untested code). --scrip1.d import std.stdio; writefln(i); ---- --main.d import std.file; import std.script; void main(){ Script s = new Script(cast(ubyte[]) read("script1.d")); assert(!s.validate); int i = 1; assert(s.validate); s.compile(); s.execute(); // output 1 } ----Doesn't this work?? import std.file; import std.script; Script s = new Script(cast(ubyte[]) read("script1.d")); s.compile(); s.execute();What is this supposed to mean?
Dec 09 2010
%u schrieb:== Quote from so (so so.do)'s articleThat wouldn't be just a script but a runtime-string-mixin (or something like that). I don't think something like that is feasible in a compiled language.This should be a bit more clear (untested code). --scrip1.d import std.stdio; writefln(i); ---- --main.d import std.file; import std.script; void main(){ Script s = new Script(cast(ubyte[]) read("script1.d")); assert(!s.validate); int i = 1; assert(s.validate); s.compile(); s.execute(); // output 1 } ----Doesn't this work?? import std.file; import std.script; Script s = new Script(cast(ubyte[]) read("script1.d")); s.compile(); s.execute();What is this supposed to mean?
Dec 09 2010
== Quote from Daniel Gibson (metalcaedes gmail.com)'s article%u schrieb:Yes, I forgot to change the s.execute to s.mixin :)== Quote from so (so so.do)'s articleThat wouldn't be just a script but a runtime-string-mixin (or something like that).This should be a bit more clear (untested code). --scrip1.d import std.stdio; writefln(i); ---- --main.d import std.file; import std.script; void main(){ Script s = new Script(cast(ubyte[]) read("script1.d")); assert(!s.validate); int i = 1; assert(s.validate); s.compile(); s.execute(); // output 1 } ----Doesn't this work?? import std.file; import std.script; Script s = new Script(cast(ubyte[]) read("script1.d")); s.compile(); s.execute();What is this supposed to mean?I don't think something like that is feasible in a compiled language.how about something like this: s.execute(i); Where in the script i will be the first arg in main? That way the compiler knows which variables to export.
Dec 09 2010
%u schrieb:== Quote from Daniel Gibson (metalcaedes gmail.com)'s articleI guess something like that is possible. I'd prefer something like s.call("main", i); and also s.call("foo", 42, x); though - so you can define multiple functions in a script and call them. Or maybe, with more magic and support within the D compiler s.main(i); s.foo(42,x); But that means that the compiler needs to know the Script type, create a class for each script that contains the functions called on the script ("main", "foo"), create stubs for them that either do something like call("foo",i) or, if no function foo with an appropriate argument is found in the script, throws an exception.. Probably possible, but certainly not easy. The first suggestion however (s.call("foo", i)) should be possible without support in the D compiler, all the work would be done in the Script class. Still not trivial, of course, especially with arguments for called functions and their type etc.%u schrieb:Yes, I forgot to change the s.execute to s.mixin :)== Quote from so (so so.do)'s articleThat wouldn't be just a script but a runtime-string-mixin (or something like that).This should be a bit more clear (untested code). --scrip1.d import std.stdio; writefln(i); ---- --main.d import std.file; import std.script; void main(){ Script s = new Script(cast(ubyte[]) read("script1.d")); assert(!s.validate); int i = 1; assert(s.validate); s.compile(); s.execute(); // output 1 } ----Doesn't this work?? import std.file; import std.script; Script s = new Script(cast(ubyte[]) read("script1.d")); s.compile(); s.execute();What is this supposed to mean?I don't think something like that is feasible in a compiled language.how about something like this: s.execute(i); Where in the script i will be the first arg in main? That way the compiler knows which variables to export.
Dec 09 2010
== Quote from Daniel Gibson (metalcaedes gmail.com)'s articleI guess something like that is possible. I'd prefer something like s.call("main", i); and also s.call("foo", 42, x); though - so you can define multiple functions in a script and call them.Of course, I was thinking that if you omit the function name it would default to main, but that would prohibit the use of a string as first argument :)Or maybe, with more magic and support within the D compiler s.main(i); s.foo(42,x); But that means that the compiler needs to know the Script type, create a class for each script that contains the functions called on the script ("main", "foo"), create stubs for them that either do something like call("foo",i) or, if no function foo with an appropriate argument is found in the script, throws an exception.. Probably possible, but certainly not easy. The first suggestion however (s.call("foo", i)) should be possible without support in the D compiler, all the work would be done in the Script class. Still not trivial, of course, especially with arguments for called functions and their type etc.I would be more than happy with only the first method :) Would DMDscript help?
Dec 09 2010
Daniel Gibson wrote:Or maybe, with more magic and support within the D compiler s.main(i); s.foo(42,x);We can do that today - write an opDispatch that forwards to an associative array. It's actually pretty trivial.
Dec 09 2010
Adam Ruppe schrieb:Daniel Gibson wrote:Cool. I should get familiar with D2 one day ;-)Or maybe, with more magic and support within the D compiler s.main(i); s.foo(42,x);We can do that today - write an opDispatch that forwards to an associative array. It's actually pretty trivial.
Dec 09 2010
I guess something like that is possible. I'd prefer something like s.call("main", i); and also s.call("foo", 42, x); though - so you can define multiple functions in a script and call them. Or maybe, with more magic and support within the D compiler s.main(i); s.foo(42,x); But that means that the compiler needs to know the Script type, create a class for each script that contains the functions called on the script ("main", "foo"), create stubs for them that either do something like call("foo",i) or, if no function foo with an appropriate argument is found in the script, throws an exception.. Probably possible, but certainly not easy. The first suggestion however (s.call("foo", i)) should be possible without support in the D compiler, all the work would be done in the Script class. Still not trivial, of course, especially with arguments for called functions and their type etc.The actual use case in my scenario is manipulating your program. not necessarily the other way around. class ScriptBinary { void run() {..} } // [modules] is the list of modules you give access to script // if [modules] contains "std", script can access "std" and it is child modules. ScriptBinary compile(string filename, string[] modules, ...) { ... } -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 09 2010
so schrieb:I think for a proper general purpose scripting solution (like one would expect in std.script) both ways are needed. But you're right, of course you need a way to tell the script what modules (and maybe also functions/delegates so it can call local functions in your code, but not all of them) it may access and how.I guess something like that is possible. I'd prefer something like s.call("main", i); and also s.call("foo", 42, x); though - so you can define multiple functions in a script and call them. Or maybe, with more magic and support within the D compiler s.main(i); s.foo(42,x); But that means that the compiler needs to know the Script type, create a class for each script that contains the functions called on the script ("main", "foo"), create stubs for them that either do something like call("foo",i) or, if no function foo with an appropriate argument is found in the script, throws an exception.. Probably possible, but certainly not easy. The first suggestion however (s.call("foo", i)) should be possible without support in the D compiler, all the work would be done in the Script class. Still not trivial, of course, especially with arguments for called functions and their type etc.The actual use case in my scenario is manipulating your program. not necessarily the other way around. class ScriptBinary { void run() {..} } // [modules] is the list of modules you give access to script // if [modules] contains "std", script can access "std" and it is child modules. ScriptBinary compile(string filename, string[] modules, ...) { ... }
Dec 09 2010
I think for a proper general purpose scripting solution (like one would expect in std.script) both ways are needed.Oh you are right, supporting one side is a dead end. class ScriptBinary { void run() {..} void call(...) {...} void opDispatch(...) {... call(); } // As Adam also pointed out. } -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 09 2010
This should be a bit more clear (untested code). --scrip1.d import std.stdio; writefln(i); ---- --main.d import std.file; import std.script; void main(){ Script s = new Script(cast(ubyte[]) read("script1.d")); assert(!s.validate); int i = 1; assert(s.validate); s.compile(); s.execute(); // output 1 } ----Oh, D doesn't have a scripting module as far as i know. Sorry i thought you were implying something, knowing the the topic is touchy for some people that has no idea how serious is this tiny issue. -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 09 2010
== Quote from so (so so.do)'s articleI was kind of implying the script module existed, but I'm not really touchy about that ;PThis should be a bit more clear (untested code). --scrip1.d import std.stdio; writefln(i); ---- --main.d import std.file; import std.script; void main(){ Script s = new Script(cast(ubyte[]) read("script1.d")); assert(!s.validate); int i = 1; assert(s.validate); s.compile(); s.execute(); // output 1 } ----Oh, D doesn't have a scripting module as far as i know. Sorry i thought you were implying something, knowing the the topic is touchy for some people that has no idea how serious is this tiny issue.
Dec 09 2010