ActiveX Lisp Server Demo

(c) 98, Thomas Mahler

Introduction

The Java class Server forms an interface layer to the virtual machine. This Class is used by both the Command Line Lisp interpreter (lisp.java) and the applet version (webLisp.java).
The same class can be registered as an ActiveX component to provide the webLisp VM as an ActiveX Server in any WinNT/95 based software.
If you don't use MS Internet Explorer or any Browser that supports ActiveX controls continue reading in the section "Installation"


Sample in VBScript

This sample shows how you can include the object in VBSript on a web page.
You can run this sample only in MS Internet Explorer or any Browser that supports ActiveX controls.
The code in VisualBasic or VB for Applications would use the statement "Set objLisp = createobject("weblisp.server")" for instanciating the object and not the HTML <object>-tag, but scripting this object would be the same as here. For Scripting details see the Interface documentation below.

Input/Output pane
delete everything in this textbox and enter some valid lisp code, e.g. (fac 10).

 


Installation

This sample will only run properly if you have installed all necessary components as described here:

  1. All the *.class files of WebLisp have to be in the directory <WinDir>\Java\Trustlib
  2. At the Command Prompt change directory to <WinDir>\Java\Trustlib (e.g. cd winnt\Java\Trustlib)
  3. Run javareg /register /class:server /progid:weblisp.server /clsid:{d3a9a150-7714-11d1-8d99-204c4f4f5020}
  4. Reload this page. You should get no script errors.
    You can then enter some example code (e.g. (fac 10) or (Y facY 10) ) and press the "Eval !" Button to get the code executed

Interface documentation

The weblisp.server Object provides the following methods and properties:

Properties:
.about
String containing basic copyright message
.helpText
short help text describing the most basic functions of the VM.
 
Methods:
.start()
The Start method will initialize the VM and load the initial environment with some usefull functions for testing. Try (fac 10), (a 3 3) or (tak 12 6 3).
.eval(String)
assumes the String argument to a valid lisp expression, evaluates it and return the result as a String object. Any errors ocuring in the process will be displaed. The only critical point with this method is, that it is not safe for nonterminating computations and will go on computing for ever. If you wish to experiment with possible nonterminating computations use the redstep() method
.read(String)
tries to read, parse and compile the given String. If successful it will return an empty string "", and error message otherwise.
as a sideeffect of the parsing process a webLisp VM task will be created that containes the parsed and compiled object. This object can than be evaluated with the redstep() method. To print ou the parsed and compiled object use .toString().
.redstep()
performes one reduction step of the VM. redstep returns true if the evaluation is finished, false otherwise. Redstep is non blocking an can thus be used in a multithreaded environment. It is easy to stop such an evaluation with a call to the .stop() method. If redstep returns true, the computaion is finished and the result can be displayed with the toString() method
.stop()
resets the VM and destroys all pending computations.
.toString()
returns the root object of the VM as a formated lisp expression. use this method to display the startup object or the results of any computation.

VisualBasic sample

The following sample code in VisualBasic shows how to incorporate this code in your applications:
This sample uses a single form, two textboxes Text1 for input and Text2 for output and two command buttons CommandStopServer and CommandExit. To use this code just build up a form with these elements, name them as given here and copy the following source code into the form's code view.

' ****************************************************************************
' Copyright (c) 1998 by Thomas Mahler.  All rights reserved.
' 
' THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
' OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
'  
' Permission is hereby granted to use or copy this program for non-commercial
' purpose, provided the above notices are retained on all copies.
' Permission to modify the code is granted, provided the above notices 
' are retained. If you intend to distibrute modified versions of this code or 
' to use this program for commercial purposes contact the author 
' of this software for permission and further legal arrangements.
' 
' mailto:thomas.mahler@essen.netsurf.de
' http://www.techno.net/pcl
' ****************************************************************************
Option Explicit
Dim obj As Object

Private Sub evaluate()	 'evaluate uses the blocking eval method. be careful in using it
    MousePointer = vbHourglass
    Text2.Text = obj.eval(Text1.Text) 	'call the blocling eval method
    MousePointer = vbDefault
    Text1.SetFocus
End Sub

Private Sub evaluate1() 	'this version is nonblocking and allows stoping of the server
    MousePointer = vbHourglass
    Dim strRet As String
    strRet = obj.read(Text1.Text) 		'call read for parsing and compiling
    Text2.Text = strRet
    If strRet = "" Then	'if strRet ="" the compilation was successful, start computation
        Do While Not obj.redstep 	'if redstep returns true evaluation is finished
            DoEvents	'give control to the OS, so that evaluation may be stopped with CommandStopServer_Click
        Loop
        Text2.Text = obj.toString	'print out result
    End If
    MousePointer = vbDefault
    Text1.SetFocus
End Sub


Private Sub CommandExit_Click()
    End
End Sub

Private Sub CommandStopServer_Click()
    obj.stop	'call the stop method to reset the webLisp VM
End Sub

Private Sub Form_Load()
    On Error GoTo err_Form_Load
    Set obj = CreateObject("weblisp.server") 	'instanciate the weblisp.server ActiveX server
    obj.start	'call start for loading the initial environment
    Text2.Text = obj.about	'get about property
    Exit Sub
    'if initialising failes give help message for proper installation:
    err_Form_Load:
    MsgBox "Initializing of weblisp.server failed. Check for proper installation of all components." + Chr(13) + _
    "1. All Java Classes must be in <%windir%>\java\trustlib." + Chr(13) + _
    "2. run javareg /register /class:server /progid:weblisp.server" + Chr(13) + _
    "3. Start the ActiveX Client again", vbExclamation
    CommandExit_Click
End Sub

' if <return> is pressed while the focus is in Text1 start the evaluation
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
    evaluate1	 ' replace by evaluate if you want to experiment with the blocking version
    End If
End Sub