Using Script Libraries with LS2J
This demonstrates how you might create your own Java™ Script Library and include it in your LotusScript® application using LS2J.
- Create a Java™ Script Library
called xlib containing the following:
public class calculator { public int add(int a, int b) { return a + b; } public int div(int a, int b) { return a / b; } public int mul(int a, int b) { return a * b; } public int sub(int a, int b) { return a - b; } }
- Create a LotusScript® Agent
which uses the library
Option Public Use "xlib" Uselsx "*javacon" Sub Initialize Dim mySession As JavaSession Dim myClass As JavaClass Dim calculator As JavaObject Dim a,b,c As Integer Set mySession = New JavaSession() Set myClass = mySession.GetClass("calculator") Set calculator = myClass.CreateObject() a = 10 b = 5 c = calculator.mul(a,b) MessageBox "a * b = " & c End Sub
Run the program. The answer is 50.
Description of the USE statement
The syntax of the LotusScript® USE statement is:
USE <script_library>
The Use statement examines the type of the Script Library. If the Script Library contains LotusScript®, processing proceeds as before. If the Script Library contains Java™ classes, the contained Java™ classes are available to the LotusScript® program by using LS2J.
Note: The restriction on using the LotusScript® "Use" statement to incorporate
a Script Library containing Java™ has
been lifted.