(c) 98, Thomas Mahler
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"
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.
This sample will only run
properly if you have installed all necessary components as
described here:
The weblisp.server Object provides the following methods and properties:
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