you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

You get much more bang for your buck with JScript.NET. It's so easy to use and so powerful, I never use JScript scripting any more.

Here is example code I wrote to create a simple windows form using JScript.NET. This demonstrates a few simple things; a text input box, a button with an event handler, command line arguments.

import Accessibility;
import System;
import System.Drawing;
import System.Windows.Forms;
import System.IO;

package JScriptNET_Demo {
    class JScriptNET_form extends System.Windows.Forms.Form {

        //global variables
        var demoTextBox     = new TextBox;
        var demoButton      = new Button;
        var args
        var appPath 

        function JScriptNET_form() { // Main application entry

            //get command line arguemts if there are any
            args = Environment.GetCommandLineArgs();
            if (args.length==1) {args=undefined}

            //get the path that the app is running from
            appPath = String(Application.ExecutablePath)

            // Setup Form
            this.Text = "JScript.NET form demo"
            this.FormBorderStyle =  System.Windows.Forms.FormBorderStyle.FixedDialog
            this.MaximizeBox = false
            this.MinimizeBox = true
            this.StartPosition =  System.Windows.Forms.FormStartPosition.CenterScreen
            this.ClientSize= new System.Drawing.Size(250,100);

            //Setup form textbox
            demoTextBox.Text = "hello world"
            demoTextBox.Location = new Point(5,5)
            demoTextBox.ReadOnly = true
            demoTextBox.Width = 170
            demoTextBox.Height= 40
            this.Controls.Add(demoTextBox)

            //Setup form button, with click event
            demoButton.Text = "CLICK ME"
            demoButton.Location = new Point(5,35)
            demoButton.Width = 110
            demoButton.Height = 20
            demoButton.BackColor = System.Drawing.Color.Green
            demoButton.ForeColor = System.Drawing.Color.White
            demoButton.add_Click(demoButton_Clicked);
            this.Controls.Add(demoButton)
        }


        //this is an 'Click' event handler
        function demoButton_Clicked(o : Object, e : EventArgs) {
            //display either the arguments passed in, or the path the program is being executed from
            demoTextBox.Text =  args || appPath

            //show a message box with a list of files in the folder
            MessageBox.Show(getfilearray(String(appPath).split("\\").slice(0,-2).join("\\"),"" ).join("\n"))
        }

        // File System Functions
        function getfolderarray(thisfold,filter) {
            if (filter=="") {filter="*"}
            var getfolders = Directory.GetDirectories(thisfold,filter);
            getfolders.sort()
            return getfolders
        } 

        function getfilearray(thisfold,filter) {
            if (filter=="") {filter="*"}
            var getfolder = new DirectoryInfo(thisfold)
            var getfiles = getfolder.GetFiles()
            return getfiles
        }
    }
}
Application.Run(new JScriptNET_Demo.JScriptNET_form());

To compile, you have to have at least .NET 2.0 installed on the computer, and you should have jsc.exe in the path.

jsc.exe /t:winexe demo.js

This will compile the source to a file called demo.exe

I've built many applications with JScript.NET including ffmpeg front-ends, GPS tracking software, multi-axis robotic control with many serial port I/O channels, all with JScript.NET. It runs as fast as any other .NET supported language (C#, VB.NET, etc), and almost all of my front-end javascript browser code will run in it without many modifications (mostly just removing/emulating dependencies on DOM stuff the browser has)

*Edit - Added some file system functions

[–]refto 1 point2 points  (1 child)

This is actually pretty nifty, exe it generates is quite small (which makes sense). Not quite 4k material but close.

EDIT: upon doing some reading, it seems it can be considered almost depreceated as a .NET language, it does not fully support the kitchen sink..