www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Embed JavaScript into D

reply "Jeroen Bollen" <jbinero gmail.com> writes:
Is there a way I can embed javascript into my D application? I 
basically want to create a modular application which allows 
adding and removing plugins by dragging and dropping them into a 
folder. I love the idea of them being editable on the fly.
Nov 04 2013
next sibling parent reply "Dicebot" <public dicebot.lv> writes:
On Monday, 4 November 2013 at 19:35:55 UTC, Jeroen Bollen wrote:
 Is there a way I can embed javascript into my D application? I 
 basically want to create a modular application which allows 
 adding and removing plugins by dragging and dropping them into 
 a folder. I love the idea of them being editable on the fly.
Don't know about JavaScript but there is a well-maintained Lua integration library : https://github.com/JakobOvrum/LuaD Also with dmd compilation speeds you actually can just compiler shared library binaries of the fly from D plugin sources and get pretty much the same thing with pure D.
Nov 04 2013
parent reply "Jeroen Bollen" <jbinero gmail.com> writes:
On Monday, 4 November 2013 at 19:45:23 UTC, Dicebot wrote:
 On Monday, 4 November 2013 at 19:35:55 UTC, Jeroen Bollen wrote:
 Is there a way I can embed javascript into my D application? I 
 basically want to create a modular application which allows 
 adding and removing plugins by dragging and dropping them into 
 a folder. I love the idea of them being editable on the fly.
Don't know about JavaScript but there is a well-maintained Lua integration library : https://github.com/JakobOvrum/LuaD Also with dmd compilation speeds you actually can just compiler shared library binaries of the fly from D plugin sources and get pretty much the same thing with pure D.
I would still prefer to use a scripting language though because of a lot of removed complexity for simple tasks.
Nov 04 2013
parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Monday, 4 November 2013 at 20:18:19 UTC, Jeroen Bollen wrote:
 On Monday, 4 November 2013 at 19:45:23 UTC, Dicebot wrote:
 On Monday, 4 November 2013 at 19:35:55 UTC, Jeroen Bollen 
 wrote:
 Is there a way I can embed javascript into my D application? 
 I basically want to create a modular application which allows 
 adding and removing plugins by dragging and dropping them 
 into a folder. I love the idea of them being editable on the 
 fly.
Don't know about JavaScript but there is a well-maintained Lua integration library : https://github.com/JakobOvrum/LuaD Also with dmd compilation speeds you actually can just compiler shared library binaries of the fly from D plugin sources and get pretty much the same thing with pure D.
I would still prefer to use a scripting language though because of a lot of removed complexity for simple tasks.
LuaD is great. There is also https://bitbucket.org/ariovistus/pyd/
Nov 04 2013
parent reply "Jeroen Bollen" <jbinero gmail.com> writes:
On Monday, 4 November 2013 at 20:43:46 UTC, John Colvin wrote:
 On Monday, 4 November 2013 at 20:18:19 UTC, Jeroen Bollen wrote:
 On Monday, 4 November 2013 at 19:45:23 UTC, Dicebot wrote:
 On Monday, 4 November 2013 at 19:35:55 UTC, Jeroen Bollen 
 wrote:
 Is there a way I can embed javascript into my D application? 
 I basically want to create a modular application which 
 allows adding and removing plugins by dragging and dropping 
 them into a folder. I love the idea of them being editable 
 on the fly.
Don't know about JavaScript but there is a well-maintained Lua integration library : https://github.com/JakobOvrum/LuaD Also with dmd compilation speeds you actually can just compiler shared library binaries of the fly from D plugin sources and get pretty much the same thing with pure D.
I would still prefer to use a scripting language though because of a lot of removed complexity for simple tasks.
LuaD is great. There is also https://bitbucket.org/ariovistus/pyd/
The reason I'm not picking up any of these is purely based on my opinion, I hate developping in LUA or Python. Are there no JavaScript / PHP bindings available yet?
Nov 04 2013
parent reply "Dicebot" <public dicebot.lv> writes:
On Monday, 4 November 2013 at 20:57:28 UTC, Jeroen Bollen wrote:
 The reason I'm not picking up any of these is purely based on 
 my opinion, I hate developping in LUA or Python. Are there no 
 JavaScript / PHP bindings available yet?
None that are widely known at least. There can always be some hidden treasures on GitHub of course. But general attitude to PHP and JS in this community does not seem very friendly, so this stuff would be surprising to find.
Nov 04 2013
parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Monday, 4 November 2013 at 21:07:38 UTC, Dicebot wrote:
 On Monday, 4 November 2013 at 20:57:28 UTC, Jeroen Bollen wrote:
 The reason I'm not picking up any of these is purely based on 
 my opinion, I hate developping in LUA or Python. Are there no 
 JavaScript / PHP bindings available yet?
 But general attitude to PHP and JS in this community does not 
 seem very friendly.
Yup. I'm no massive fan of Lua or Python, but in comparison to php and JS they look like works of genius.
Nov 04 2013
prev sibling next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Monday, 4 November 2013 at 19:35:55 UTC, Jeroen Bollen wrote:
 Is there a way I can embed javascript into my D application?
You could use any C javascript lib too, but for ones already wrapped or something, I know there's a few D implementations of javascript: dmdscript <http://www.digitalmars.com/dscript/index.html> (written in D1 but there's two or three ports out there to D2), an experimental implementation by Maxime Chevalier-Boisvert <http://dconf.org/talks/chevalier_boisvert.html>, and I think a couple more. I also wrote a language that is kinda like javascript but isn't actually the same and is buggy... but might be easier to integrate https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff get script.d and jsvar.d, don't need the other files. usage: import arsd.jsvar; import arsd.script; void main() { var globals = var.emptyObject; // add a variadic write function... globals.write._function = (var _this, var[] args) { import std.conv; import std.stdio; string s; foreach(a; args) s ~= a.get!string; writeln(s); return var(null); }; // you can also add D functions pretty straightforwardly globals.otherFunction = (int a, int b) { return a+b; }; // can also set values easily in D globals.yourValue = 10; import std.file; // read the user's code file interpret(readText("scriptcode.js"), globals); /* // suppose the code there is: // the syntax is kinda like javascript and kinda like D // the concat operator is D style, but function decls are JS style function foo(name) { return "hello, " ~ name; } // set a global variable too var myname = "adam"; // my language requires variables be declared, even if global */ // and functions/variable set in the script code are also available via the globals object // extra parens are needed to call script funs because D's property is broken auto message = globals.foo()(globals.myname); // calls the script function with a script variable import std.stdio; writeln(message); // write what the script returned globals.write()(globals.foo()("D code")); // can also call it with D variables/data } If you use my little language, you'll probably find bugs, but I think it is about as easy as you can get when interfacing with D: the jsvar module gives you a var type, in D, that works very similarly to the javascript style var in the script language (except the double parens needed when calling a function) so the line can be easily blurred between native and script functions, as you see here. Compile easily too: dmd yourfile.d jsvar.d script.d
Nov 04 2013
parent reply Max Klyga <email domain.com> writes:
On 2013-11-04 21:20:46 +0000, Adam D. Ruppe said:

 On Monday, 4 November 2013 at 19:35:55 UTC, Jeroen Bollen wrote:
 Is there a way I can embed javascript into my D application?
You could use any C javascript lib too, but for ones already wrapped or something, I know there's a few D implementations of javascript: dmdscript <http://www.digitalmars.com/dscript/index.html> (written in D1 but there's two or three ports out there to D2)
D1 version is now on github: https://github.com/DigitalMars/DMDScript D2 version: http://dsource.org/projects/dmdscript-2/ pretty sure it will need tweaks to compile with current DMD version You could rather easyly embed Mozilla Spidermonkey engine, as it provides a C api and D work great with C
Nov 04 2013
parent reply "Jeroen Bollen" <jbinero gmail.com> writes:
On Monday, 4 November 2013 at 22:22:32 UTC, Max Klyga wrote:
 On 2013-11-04 21:20:46 +0000, Adam D. Ruppe said:

 On Monday, 4 November 2013 at 19:35:55 UTC, Jeroen Bollen 
 wrote:
 Is there a way I can embed javascript into my D application?
You could use any C javascript lib too, but for ones already wrapped or something, I know there's a few D implementations of javascript: dmdscript <http://www.digitalmars.com/dscript/index.html> (written in D1 but there's two or three ports out there to D2)
D1 version is now on github: https://github.com/DigitalMars/DMDScript D2 version: http://dsource.org/projects/dmdscript-2/ pretty sure it will need tweaks to compile with current DMD version You could rather easyly embed Mozilla Spidermonkey engine, as it provides a C api and D work great with C
I'm probably going with spidermonkey then. Didn't really know it had a C API... Thanks. :P
Nov 04 2013
parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 5 November 2013 at 06:36:48 UTC, Jeroen Bollen wrote:
 I'm probably going with spidermonkey then. Didn't really know 
 it had a C API... Thanks. :P
If your bindings end up being reusable, be sure to post them here so next time someone asks this, I can link to that too!
Nov 05 2013
prev sibling next sibling parent Dejan Lekic <dejan.lekic gmail.com> writes:
On Mon, 04 Nov 2013 20:35:53 +0100, Jeroen Bollen wrote:

 Is there a way I can embed javascript into my D application? I basically
 want to create a modular application which allows adding and removing
 plugins by dragging and dropping them into a folder. I love the idea of
 them being editable on the fly.
Check out this presentation: http://dconf.org/2013/talks/ chevalier_boisvert.html Source code: https://github.com/maximecb/Higgs Also, there is the DMScript project at DSource: http://dsource.org/ projects/dmdscript-2/
Nov 04 2013
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2013-11-04 20:35, Jeroen Bollen wrote:
 Is there a way I can embed javascript into my D application? I basically
 want to create a modular application which allows adding and removing
 plugins by dragging and dropping them into a folder. I love the idea of
 them being editable on the fly.
I have some bindings and simple wrappers for Ruby, if that is of interest: https://github.com/jacob-carlborg/orbit/tree/master/ruby -- /Jacob Carlborg
Nov 05 2013