| 1 | /* |
|---|
| 2 | * Main.java |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2008 Ville Voutilainen |
|---|
| 5 | * $Id: Main.java 12307 2009-12-25 21:54:31Z ehuelsmann $ |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or |
|---|
| 8 | * modify it under the terms of the GNU General Public License |
|---|
| 9 | * as published by the Free Software Foundation; either version 2 |
|---|
| 10 | * of the License, or (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | import org.armedbear.lisp.*; |
|---|
| 23 | |
|---|
| 24 | public class Main |
|---|
| 25 | { |
|---|
| 26 | /** |
|---|
| 27 | * This example creates an Interpreter instance, loads our |
|---|
| 28 | * lisp code from a file and then looks up a function defined |
|---|
| 29 | * in the loaded lisp file and executes the function. |
|---|
| 30 | * |
|---|
| 31 | * The function takes a single parameter and invokes a java method |
|---|
| 32 | * on the object provided. We provide our Main object as the parameter. |
|---|
| 33 | * |
|---|
| 34 | */ |
|---|
| 35 | public static void main(String[] argv) |
|---|
| 36 | { |
|---|
| 37 | try |
|---|
| 38 | { |
|---|
| 39 | Main thisObject = new Main(); |
|---|
| 40 | Interpreter interpreter = Interpreter.createInstance(); |
|---|
| 41 | interpreter.eval("(load \"lispfunctions.lisp\")"); |
|---|
| 42 | // the function is not in a separate package, thus the |
|---|
| 43 | // correct package is CL-USER. Symbol names are |
|---|
| 44 | // upper case. Package needs the prefix, because java |
|---|
| 45 | // also has a class named Package. |
|---|
| 46 | org.armedbear.lisp.Package defaultPackage = |
|---|
| 47 | Packages.findPackage("CL-USER"); |
|---|
| 48 | Symbol voidsym = |
|---|
| 49 | defaultPackage.findAccessibleSymbol("VOID-FUNCTION"); |
|---|
| 50 | Function voidFunction = (Function) voidsym.getSymbolFunction(); |
|---|
| 51 | voidFunction.execute(new JavaObject(thisObject)); |
|---|
| 52 | } |
|---|
| 53 | catch (Throwable t) |
|---|
| 54 | { |
|---|
| 55 | System.out.println("exception!"); |
|---|
| 56 | t.printStackTrace(); |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | public int addTwoNumbers(int a, int b) |
|---|
| 60 | { |
|---|
| 61 | throw new RuntimeException("Exception from java code"); |
|---|
| 62 | } |
|---|
| 63 | } |
|---|