RetroBASIC

Offtopic => Offtopic => Topic started by: Tomaaz on August 03, 2016, 10:00:31 PM

Title: JavaScript standalone interpreters
Post by: Tomaaz on August 03, 2016, 10:00:31 PM
Has anyone tried JavaScript outside web browsers? There is Node.js, of course, but JSDB seems to be a very compact interpreter. The only problem I had with it was regular expressions not working properly. Apart from that (and the fact that it's a bit dated) it's a nice tool for scripting and plying with JavaScript.
Title: Re: JavaScript standalone interpreters
Post by: wang renxin on August 04, 2016, 01:17:31 AM
Node.js has a standalone distribution in a single EXE too. I'll take a try and test among Node.js, Python, Ruby to choose one as a quick prototyping tool for web backend development.
Title: Re: JavaScript standalone interpreters
Post by: Ed Davis on August 04, 2016, 05:04:05 PM
Has anyone tried JavaScript outside web browsers? There is Node.js, of course, but JSDB seems to be a very compact interpreter. The only problem I had with it was regular expressions not working properly. Apart from that (and the fact that it's a bit dated) it's a nice tool for scripting and plying with JavaScript.

A few that I've played with:

Duktape
http://duktape.org/

mujs
https://github.com/ccxvii/mujs

42tiny-js
https://github.com/ardi69/42tiny-js


But I keep coming back to Python.  The more I use it, the more I appreciate it.
Title: Re: JavaScript standalone interpreters
Post by: Tomaaz on August 05, 2016, 12:07:37 PM
Node.js has a standalone distribution in a single EXE too.

Yes, but Node's been created for a slightly different things.

But I keep coming back to Python.  The more I use it, the more I appreciate it.

 ;) But for me Ruby's syntax still makes much more sense. It's a shame that Ruby doesn't exist outside the web. There are nice projects based on it (Shoes, SonicPi), but you can't really compare Ruby with Python in terms of available libraries. Thanx for the links to the JavaScript interpreters. Not exactly what I want (I would prefer fully featured distribution), but it's good to know that things like that exist. ;)
Title: Re: JavaScript standalone interpreters
Post by: Tomaaz on August 09, 2016, 02:04:37 PM
I've just found Gjs (https://wiki.gnome.org/Projects/Gjs). In the repositories. Ready to use and looks like something still in development.
Title: Re: JavaScript standalone interpreters
Post by: Cybermonkey on August 10, 2016, 06:35:28 PM
I used Node-Webkit (now known as NW.js) to build desktop applications.
Look here: http://nwjs.io/
Title: Re: JavaScript standalone interpreters
Post by: Aurel on August 10, 2016, 10:09:21 PM
...and do you can show us your example Cyb?
this smell to me to Cromium html control( dll) connected with java script to build
so called desktop app, long time ago i see something similar but with php linked with something
i forget...
Title: Re: JavaScript standalone interpreters
Post by: ScriptBasic on August 11, 2016, 03:18:48 AM
Quote from: Ed
But I keep coming back to Python.  The more I use it, the more I appreciate it.

Are you using Python for web development or utility work?

Curious, have you played around with Script BASIC any further?
Title: Re: JavaScript standalone interpreters
Post by: Tomaaz on August 11, 2016, 11:38:32 AM
...and do you can show us your example Cyb?

I would like to see a piece of code, too.

this smell to me to Cromium html control( dll) connected with java script to build
so called desktop app, long time ago i see something similar but with php linked with something
i forget...

Do you mean PHP and Gtk server? Slightly different thing.
Title: Re: JavaScript standalone interpreters
Post by: Aurel on August 11, 2016, 05:09:30 PM
No GTK...this use bind to native win api...and I find it
it is called WinBinder ..if i remember this thing work very well on windows
i will download new version and try:
http://winbinder.org/

          
     

Key benefits

    * Large installed base of PHP programmers.
    * No compiling and linking steps necessary: just code and run.
    * Access to the vast range of existing PHP functions and extensions, including databases, graphics, web functions, XML, PDF, and much more.
    * A small set of WinBinder functions encapsulates many complex aspects of the Windows API and makes programming for Windows an easy task.
    * Provides 100% native Windows classes and controls.
    * Interfaces directly to the Window API. This means fast execution, no extra libraries and no installation required.
    * Supports both procedural and object-oriented programming models.
    * High performance, compares favorably to most scripting languages.
    * Produces standalone applications that can be easily installed and removed with no reboot.
    * Small footprint. A simple Windows application, complete with the PHP runtime and SQLite extension, is smaller than 700 kB (zipped).
    * A database-independent framework allows easy coding (no SQL knowledge is necessary) and smooth integration with the WinBinder code.
    * No database server required if using SQLite.
    * Does not need to use to the Windows registry, but may use it if necessary.
Title: Re: JavaScript standalone interpreters
Post by: Tomaaz on August 11, 2016, 08:38:23 PM
I used Node-Webkit (now known as NW.js) to build desktop applications.
Look here: http://nwjs.io/

OK. I've tried it. It's very slow on Linux. Takes ages to run simple "Hello World" example.
Title: Re: JavaScript standalone interpreters
Post by: ScriptBasic on August 11, 2016, 10:59:51 PM
UltraEdit has done a nice job of embedding JavaScript into their editor.

My plan was after the Perl extension module for Script BASIC was to do a JavaScript extension but array sort got in the way and I never got back to it. Unfortunately real life is consuming all my free time at the moment.
Title: Re: JavaScript standalone interpreters
Post by: Tomaaz on August 12, 2016, 01:55:06 PM
I used Node-Webkit (now known as NW.js) to build desktop applications.
Look here: http://nwjs.io/

OK. I've tried it. It's very slow on Linux. Takes ages to run simple "Hello World" example.

It seems to be a bit faster on my Win 10 machine. Yes, it takes several seconds to start, but apart from that it seems to be something I was looking for. Thanx a lot, Cybermonkey! :)

...and do you can show us your example Cyb?.

Aurel, it basically takes your HTML/CSS/JavaScript code and run it in a standalone window. Plus you get functions that can interact with your operating system. This example simply draws Mandelbrot Set in a standalone window, but it places the window in a specific position, set its width and height and checks if the directory named "mandelbrot" exists (if not, it is created):

Code: [Select]
<!DOCTYPE html>
<html>
<head>
<title>Mandelbrot</title>
<script>
var win = nw.Window.get();
win.x = 100;
win.y = 20;
win.width = 920;
win.height = 620;
fs = require('fs');
if (!(fs.existsSync('mandelbrot'))) {
var kat = fs.mkdirSync('mandelbrot');
}
var x = 0;
function aktywuj() {
plotno = document.getElementById("rysunek");
zawartosc = plotno.getContext("2d");
zawartosc.fillStyle = "#000000";
zawartosc.fillRect(0,0,900,600);
t = setTimeout("rysuj()", 1);
}
function rysuj() {
plotno = document.getElementById("rysunek");
zawartosc = plotno.getContext("2d");
przelx = 3 / 900;
przely = 2 / 600;
for (y = 0; y < 600; y++) {
c = 0;
a = 0;
b = 0;
z = 0;
x2 = (x - 450) / 150;
y2 = (y - 300) / 150;
while (c < 128 && z < 4) {
a2 = a * a - b * b;
b2 = 2 * a * b;
a = a2 + x2;
b = b2 + y2;
z = a * a + b * b;
c = c + 1;
}
p = c * 12;
if (p > 255) {
p = 0;
}
k = c * 8;
if (k > 255) {
k = 0;
}
l = c * 4;
if (l > 255) {
l = 0;
}
m = l.toString();
n = k.toString();
o = p.toString();
kol = "rgb(" + m + "," + n + "," + o + ")";
zawartosc.fillStyle=kol;
zawartosc.fillRect(x, y, 1, 1);
}
if (x < 900) {
x++;
t = setTimeout("rysuj()", 1);
}
}
</script>
</head>
<body onload = "aktywuj()">
<div>
<canvas id="rysunek" width="900" height="600"></canvas>
</div>
</body>
</html>
Title: Re: JavaScript standalone interpreters
Post by: Aurel on August 12, 2016, 02:14:19 PM
Quote
Aurel, it basically takes your HTML/CSS/JavaScript code and run it in a standalone window
Yes i see ...nothing new or better
Title: Re: JavaScript standalone interpreters
Post by: Tomaaz on August 12, 2016, 02:41:24 PM
Quote
Aurel, it basically takes your HTML/CSS/JavaScript code and run it in a standalone window
Yes i see ...nothing new or better

Well, it can call Node.js modules from DOM, so it is something new. And better... Better than what? If you are planning to start this "WinAPI stuff" again, I'm not gonna continue this conversation. ;)
Title: Re: JavaScript standalone interpreters
Post by: Aurel on August 12, 2016, 07:36:03 PM
Hmm this have nothing with WinApi stuff
and i really don't understand what kind of problem you have with winApi  :o
and there is no problem with this at all.
Title: Re: JavaScript standalone interpreters
Post by: ScriptBasic on August 12, 2016, 08:31:17 PM
@Tomaaz,

I put the code on my AWS server and it created a black screen and that was it. I tried it with both Firefox and Chrome.
Title: Re: JavaScript standalone interpreters
Post by: Tomaaz on August 12, 2016, 09:35:54 PM
I put the code on my AWS server and it created a black screen and that was it. I tried it with both Firefox and Chrome.

This code needs to be run by NW.js (http://nwjs.io/). A standard browser will not run this code, because the code contains functions specific to NW.js and Node.js. The black thing you can see is a canvas element, but, because a standard browser cannot understand some parts of the JavaScript code, the whole script is stopped and nothing is drawn on the canvas.
Title: Re: JavaScript standalone interpreters
Post by: ScriptBasic on August 13, 2016, 01:37:15 AM
Okay. Thanks Tomaaz for the clarification.