J Language Active Script Connector. Implements Windows script interfaces. Allows J to be used as script for various scripting hosts: cscript/wscript shell with .ijss extension or a Windows Script File job, ASP, Internet Explorer; as well as custom applications that support scripting extensions. See more at http://olegykj.sourceforge.net/.

Installation

The following steps will allow you to download the archive, install the script component and run examples.

Registration and DLL are located in JayScript/test for j601 and bin folder for j602.

Browse the test folder and run examples:

After registration the .ijss files will have a yellow J icon. (May need to re-open Windows Explorer.)

Examples

The following examples show how to use JayScript in different hosting applications.

Common to all examples, is that when JayScript is loaded by the host application, it loads the default J profile and the general/pcall addon.

There is currently only limited error handling: Issuing a common exception without description.

Windows Script Host

WSH is Windows shell for scripting languages, typically VBScript or JScript. Plain text scripts have language extensions: .vbs, .js or .ijss for JayScript.

Scripts are run either from the command prompt (MS-DOS window) or by double-clicking or selecting Open from Right-click menu.

We will start with a simple Hello World script.

«test02.ijss»=
'Echo' do__WScript 'Hello, World!'

Open command prompt, cd to the test folder and run it:

d:\>cd JayScript\test

d:\JayScript\test>test02.ijss
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Hello, World!

WScript is a "root" object, which was provided by the host application, so that script could interact with it. Echo is its method and 'Hello, World!' is argument(s).

It is equivalent to VBScript statement WScript.Echo("Hello, World!"). The invokation is done using general/pcall/disp interface that provide OLE Automation functionality.

Besides "root" objects, it is possible to access their member objects; as well as list all exposed functions and properties.

«test03.ijss»=
'Echo' do__WScript 'This is J version',LF,'  ',9!:14''
'Echo' do__WScript 'Time now is ', ":6!:0''
'Echo' do__WScript 'First ten integers: ', ": 1+i.10
'Echo' do__WScript 'Their sum (+/ 1+i.10): ', ": +/ 1+i.10

'Echo' do__WScript info__WScript ''

StdIn=: disp 'StdIn' get__WScript ''
'Echo' do__WScript 'Enter your name:'
line=. 'ReadLine' do__StdIn ''
'Echo' do__WScript 'Hello, ',line,'!'

Member-object StdIn is obtained and interned with disp, whence it is accessible the same way as a root. info applied to any object shows available operations.

d:\JayScript\test>test03.ijss
This is J version
  j601/2006-11-17/17:05
Time now is 2007 7 29 21 11 39.687
First ten integers: 1 2 3 4 5 6 7 8 9 10
Their sum (+/ 1+i.10): 55
IHost   NB. Windows Script Host Application Interface
HRESULT ScriptName BSTR* out_ScriptName
HRESULT ScriptFullName BSTR* out_ScriptFullName
HRESULT Arguments IArguments2** out_Arguments
HRESULT Version BSTR* out_Version
HRESULT BuildVersion int* out_Build
HRESULT Timeout long* out_Timeout
HRESULT Timeout long out_Timeout
HRESULT CreateObject BSTR ProgID BSTR Prefix IDispatch** out_Dispatch
HRESULT Echo SAFEARRAY pArgs
HRESULT GetObject BSTR Pathname BSTR ProgID BSTR Prefix IDispatch** out_Dispatch
HRESULT DisconnectObject IDispatch* Object
HRESULT Sleep long Time
HRESULT ConnectObject IDispatch* Object BSTR Prefix
HRESULT StdIn ITextStream** out_ppts
HRESULT StdOut ITextStream** ppts
HRESULT StdErr ITextStream** ppts
Enter your name:
test
Hello, test!

There is also a special file format WSF (Windows Scirpt File) that allows you to combine scripts in different languages, include files, process input arguments, etc.

«test01.wsf»=
<job>
<script language="JScript">
  WScript.Echo("JScript: ", 1,2,3,4)
</script>

<script language="VBScript">
  WScript.Echo "VBScript",1,2,3,4
</script>

<script language="JayScript">
  'Echo' do__WScript 'JayScript:';": +/i.3 4
</script>

<script language="VBScript">
  WScript.Echo "VBScript again",1,2,3,4
</script>

<script language="JayScript">
  'Echo' do__WScript 'JayScript again:';": +/i.3 4
</script>
</job>

d:\JayScript\test>test01.wsf
JScript:  1 2 3 4
VBScript 1 2 3 4
JayScript: 12 15 18 21
VBScript again 1 2 3 4
JayScript again: 12 15 18 21

Internet Explorer

ijss_html.png

The only root object exposed is window, which has method alert, but document can be obtained to use the write method.

Events are not implemented yet.

«test04.html»=
<html><body>
...
<hr>JayScript<br>

<script language="JayScript">
  document=: disp 'document' get__window ''
  'write' do__document ": +/i.3 4
</script>

<hr>JayScript Event (not working yet)<br>

<input type=button id=bntTest value="Call J">

<script for=bntTest event="onclick()" language="JayScript">
  'alert' do__window 'Hello from J'
</script>

</body></html>

ASP

ijss_asp.png

ASP exposes as roots its standard objects Request, Response, etc. The regular <% %> notation applies and JayScript can be combined with other scripting languages on one page.

To run this example, make the test folder available from IIS as JayScript root.

«test05.asp»=
<%@ Language="JayScript" %>
<html>
<% 
timeNow=: 3 : 0
  ": 6!:0''
)
%>
<body>

<hr>JayScript Script<br>

<script language="JayScript" runat=server>
'Write' do__Response 'executed at end'
</script>

<hr>JayScript Immediate<br>
<% 'Write' do__Response timeNow'' %>

<hr>JayScript Value<br>
<%= ": +/3 4 ?@$ 100 %>

<hr>
</body></html>

See Also


Contributed by OlegKobchenko

Interfaces/Jay Script (last edited 2008-12-08 10:45:44 by )